int fs_dupfd(int fd, int minfd) { FAR struct file *filep; int ret; /* Get the file structure corresponding to the file descriptor. */ ret = fs_getfilep(fd, &filep); if (ret < 0) { goto errout; } DEBUGASSERT(filep != NULL); /* Let file_dup() do the real work */ ret = file_dup(filep, minfd); if (ret < 0) { goto errout; } return OK; errout: set_errno(-ret); return ERROR; }
APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file, apr_file_t *old_file, apr_pool_t *p) { if (*new_file) { apr_file_close(*new_file); (*new_file)->filedes = -1; } return file_dup(new_file, old_file, p); }
sysret_t sys_open(const char* name, int flags, int mode) { sysret_t ret = file_open(name, flags, mode); if(ret.result == -1) return ret; if((ret.result = file_dup((file_t*)ret.result)) == -1) ret.err = ENOMEM; return ret; }
int sys_open(const char* name, int flags, int mode) { file_t* file = file_open(name, flags, mode); if (IS_ERR_VALUE(file)) return PTR_ERR(file); int fd = file_dup(file); if (fd < 0) return -ENOMEM; return fd; }
int sys_dup(int fd) { int r = -EBADF; file_t* f = file_get(fd); if (f) { r = file_dup(f); file_decref(f); } return r; }
int sys_openat(int dirfd, const char* name, int flags, int mode) { int kfd = at_kfd(dirfd); if (kfd != -1) { file_t* file = file_openat(kfd, name, flags, mode); if (IS_ERR_VALUE(file)) return PTR_ERR(file); int fd = file_dup(file); if (fd < 0) { file_decref(file); return -ENOMEM; } return fd; } return -EBADF; }
int sys_openat(int dirfd, const char* name, int flags, int mode) { if(name[0] == '/'){ return sys_open(name, flags, mode); } file_t* dir = file_get(dirfd); if(dir) { file_t* file = file_openat(dir->kfd, name, flags, mode); if (IS_ERR_VALUE(file)) return PTR_ERR(file); int fd = file_dup(file); if (fd < 0) return -ENOMEM; return fd; } return -EBADF; }
APR_DECLARE(apr_status_t) apr_file_dup2(apr_file_t *new_file, apr_file_t *old_file, apr_pool_t *p) { return file_dup(&new_file, old_file, p, 2); }
APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file, apr_file_t *old_file, apr_pool_t *p) { return file_dup(new_file, old_file, p, 1); }
/* sysfile_dup - duplicate fd1 to fd2 */ int sysfile_dup(int fd1, int fd2) { return file_dup(fd1, fd2); }