dev/c/ParallelsTest/10.c

35 lines
669 B
C

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#ifndef INITIAL_LIMIT
# define INITIAL_LIMIT 1025
#endif
char buf[2*INITIAL_LIMIT];
write_to_file(int id) {
char link[64];
char * links = "/proc/self/fd/";
sprintf(link, "%s", links);
sprintf(link+strlen(links), "%d", id);
//printf("link=%s\n", link);
readlink(link, buf, INITIAL_LIMIT);
//printf("buf=%s\n", buf);
close(id);
id = open(buf, O_WRONLY);
write(id, "Hello world!\n", 13);
close(id);
}
int main(int argc, char * argv[]) {
int id = open("tmp.txt", O_RDONLY);
write_to_file(id);
return (0);
}