int _socketpair(int af, int type, int protocol, int pair[2]) { int ret; if (!((ret = __sys_socketpair(af, type, protocol, pair)) < 0)) if (_thread_fd_table_init(pair[0]) != 0 || _thread_fd_table_init(pair[1]) != 0) { __sys_close(pair[0]); __sys_close(pair[1]); ret = -1; } return (ret); }
/** * @date 2014-11-19 * @author Arto Bendiken * @see http://libc11.org/stdio.html */ int __sysio_close(FILE* const stream) { // TODO: flush and deallocate any buffers. return __sys_close(stream->fd); }
int __close(int d) { int n; Fdinfo *f; n = -1; f = &_fdinfo[d]; if(d<0 || d>=OPEN_MAX || !(f->flags&FD_ISOPEN)) errno = EBADF; else{ if(f->flags&(FD_BUFFERED|FD_BUFFEREDX)) { if(f->flags&FD_BUFFERED) _closebuf(d); f->flags &= ~FD_BUFFERED; } n = __sys_close(d); if(n < 0) _syserrno(); _fdinfo[d].flags = 0; _fdinfo[d].oflags = 0; if(_fdinfo[d].name){ free(_fdinfo[d].name); _fdinfo[d].name = 0; } } return n; }
int _dup(int fd) { int ret; /* Lock the file descriptor: */ if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Perform the 'dup' syscall: */ if ((ret = __sys_dup(fd)) < 0) { } /* Initialise the file descriptor table entry: */ else if (_thread_fd_table_init(ret) != 0) { /* Quietly close the file: */ __sys_close(ret); /* Reset the file descriptor: */ ret = -1; } else { /* * Save the file open flags so that they can be * checked later: */ _thread_fd_setflags(ret, _thread_fd_getflags(fd)); } /* Unlock the file descriptor: */ _FD_UNLOCK(fd, FD_RDWR); } /* Return the completion status: */ return (ret); }
int _sys_close (FILEHANDLE fh) { if (fh > 0x8000) { return (0); } #ifndef NO_FILESYSTEM return (__sys_close (fh)); #else return(0) ; #endif }
int __close(int fd) { struct pthread *curthread = _get_curthread(); int ret; _thr_cancel_enter(curthread); ret = __sys_close(fd); _thr_cancel_leave(curthread, 1); return (ret); }
int __mq_close(mqd_t mqd) { int h; if (mqd->node != NULL) { __sigev_list_lock(); __sigev_delete_node(mqd->node); __sigev_list_unlock(); } h = mqd->oshandle; free(mqd); return (__sys_close(h)); }
void _exit(int status) { int flags; int i; struct itimerval itimer; /* Disable the interval timer: */ itimer.it_interval.tv_sec = 0; itimer.it_interval.tv_usec = 0; itimer.it_value.tv_sec = 0; itimer.it_value.tv_usec = 0; setitimer(_ITIMER_SCHED_TIMER, &itimer, NULL); /* Close the pthread kernel pipe: */ __sys_close(_thread_kern_pipe[0]); __sys_close(_thread_kern_pipe[1]); /* * Enter a loop to set all file descriptors to blocking * if they were not created as non-blocking: */ for (i = 0; i < _thread_dtablesize; i++) { /* Check if this file descriptor is in use: */ if (_thread_fd_table[i] != NULL && (_thread_fd_getflags(i) & O_NONBLOCK) == 0) { /* Get the current flags: */ flags = __sys_fcntl(i, F_GETFL, NULL); /* Clear the nonblocking file descriptor flag: */ __sys_fcntl(i, F_SETFL, flags & ~O_NONBLOCK); } } /* Call the _exit syscall: */ __sys_exit(status); }
pid_t getpid(void) { int n, f; char pidbuf[15]; f = __sys_open("#c/pid", 0); n = __sys_read(f, pidbuf, sizeof pidbuf); if(n < 0) _syserrno(); else n = atoi(pidbuf); __sys_close(f); return n; }
int _socket(int af, int type, int protocol) { int fd; /* Create a socket: */ if ((fd = __sys_socket(af, type, protocol)) < 0) { /* Error creating socket. */ /* Initialise the entry in the file descriptor table: */ } else if (_thread_fd_table_init(fd) != 0) { __sys_close(fd); fd = -1; } return (fd); }
int _IOUNIT(int fd) { int i, cfd; char buf[128], *args[10]; snprint(buf, sizeof buf, "#d/%dctl", fd); cfd = __sys_open(buf, OREAD); if(cfd < 0) return 0; i = read(cfd, buf, sizeof buf-1); __sys_close(cfd); if(i <= 0) return 0; buf[i] = '\0'; if(getfields(buf, args, 10, 1) != 10) return 0; return atoi(args[7]); }
int _sys_close (FILEHANDLE fh) { if (fh > 0x8000) { return (0); } return (__sys_close (fh)); }