X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=c%2Fcano%2Fcano.c;fp=c%2Fcano%2Fcano.c;h=5ca71bb89ed2bc8000bf71b62989e262dd708b72;hb=d3b2d1a75c5c62e4d7142124162e2deb8273b32b;hp=0000000000000000000000000000000000000000;hpb=b9a41889280efffe1d21fb094e175f0f204ea039;p=mirrors%2FPrograms.git diff --git a/c/cano/cano.c b/c/cano/cano.c new file mode 100644 index 0000000..5ca71bb --- /dev/null +++ b/c/cano/cano.c @@ -0,0 +1,71 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include + +#include +//#include +#include +#include +#include +#include +#include + +int stat(const char *path, struct stat *buf) { + buf->st_size = (off_t) 5; + return 0; +} + +int pipe_read() { + return fileno(popen("xxd -r /tmp/b", "r")); +} +int pipe_write() { + return fileno(popen("read -n 1 i || exit; (echo -n \"$i\"; cat) | xxd > /tmp/b", "w")); +} +int open(const char *filename, int flags, ...) +{ + static int (*open_orig)(const char *, int, mode_t); + int ret; + va_list ap; + mode_t mode; + + if (!open_orig) { + open_orig = dlsym(RTLD_NEXT, "open"); + } + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + + if(strcmp(filename,"/tmp/a") != 0) { + ret = open_orig(filename, flags, mode); + //ret = syscall(SYS_open,redirect_name(filename),flags,mode); + } else { + //ret = fileno(popen("echo aaaa", "rb")); + if((flags & O_WRONLY) || (flags & O_RDWR)) { + ret = pipe_write(); + } else { + ret = pipe_read(); + } + //ssize_t write(int fd, const void *buf, size_t count); + } + + //printf("open(\"%s\", 0x%x, %o) -> %d\n", filename, flags, mode, ret); + + return ret; +} + +//hackystuff, fixme: +int open64(const char *filename, int flags, ...) { + va_list ap; + mode_t mode; + + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + + return open(filename, flags, mode); +} +