int open(const char *pathname, int flags, ...) { mode_t mode = 0; if (flags & O_CREAT) { /* get mode */ va_list ap; va_start(ap, flags); mode = va_arg(ap, mode_t); va_end(ap); } return __fd_open(pathname, flags, mode); }
int __fd_openat(int basefd, const char *pathname, int flags, mode_t mode) { exe_file_t *f; int fd; if (basefd != AT_FDCWD) { exe_file_t *bf = __get_file(basefd); if (!bf) { errno = EBADF; return -1; } else if (bf->dfile) { klee_warning("symbolic file descriptor, ignoring (ENOENT)"); errno = ENOENT; return -1; } basefd = bf->fd; } if (__get_sym_file(pathname)) { /* for a symbolic file, it doesn't matter if/where it exists on disk */ return __fd_open(pathname, flags, mode); } for (fd = 0; fd < MAX_FDS; ++fd) if (!(__exe_env.fds[fd].flags & eOpen)) break; if (fd == MAX_FDS) { errno = EMFILE; return -1; } f = &__exe_env.fds[fd]; /* Should be the case if file was available, but just in case. */ memset(f, 0, sizeof *f); int os_fd = syscall(__NR_openat, (long)basefd, __concretize_string(pathname), (long)flags, mode); if (os_fd == -1) return -1; f->fd = os_fd; f->flags = eOpen; if ((flags & O_ACCMODE) == O_RDONLY) { f->flags |= eReadable; } else if ((flags & O_ACCMODE) == O_WRONLY) { f->flags |= eWriteable; } else { /* XXX What actually happens here if != O_RDWR. */ f->flags |= eReadable | eWriteable; } return fd; }