static FILE * _endopen(const char *file, const char *mode, FILE *iop, int largefile) { int plus, oflag, fd; if (iop == NULL || file == NULL || file[0] == '\0') return (NULL); plus = (mode[1] == '+'); switch (mode[0]) { case 'w': oflag = (plus ? O_RDWR : O_WRONLY) | O_TRUNC | O_CREAT; break; case 'a': oflag = (plus ? O_RDWR : O_WRONLY) | O_CREAT; break; case 'r': oflag = plus ? O_RDWR : O_RDONLY; break; default: return (NULL); } if (largefile) { fd = open64(file, oflag, 0666); /* mapped to open() for V9 */ } else { fd = open(file, oflag, 0666); } if (fd < 0) return (NULL); iop->_cnt = 0; #ifdef _LP64 iop->_file = fd; #else if (fd <= _FILE_FD_MAX) { SET_FILE(iop, fd); } else if (_file_set(iop, fd, mode) != 0) { /* errno set in _file_set() */ (void) close(fd); return (NULL); } #endif iop->_flag = plus ? _IORW : (mode[0] == 'r') ? _IOREAD : _IOWRT; if (mode[0] == 'a') { if ((lseek64(fd, 0L, SEEK_END)) < 0) { (void) close(fd); return (NULL); } } iop->_base = iop->_ptr = NULL; /* * Sys5 does not support _bufsiz * * iop->_bufsiz = 0; */ return (iop); }
FILE * fdopen(int fd, const char *type) /* associate file desc. with stream */ { /* iop doesn't need locking since this function is creating it */ FILE *iop; char plus; unsigned char flag; /* Sets EBADF for bad fds */ if (fcntl(fd, F_GETFD) == -1) return (NULL); if ((iop = _findiop()) == 0) { errno = ENOMEM; return (NULL); } switch (type[0]) { default: iop->_flag = 0; /* release iop */ errno = EINVAL; return (NULL); case 'r': flag = _IOREAD; break; case 'a': (void) lseek64(fd, (off64_t)0, SEEK_END); /*FALLTHROUGH*/ case 'w': flag = _IOWRT; break; } if ((plus = type[1]) == 'b') /* Unix ignores 'b' ANSI std */ plus = type[2]; if (plus == '+') flag = _IORW; iop->_flag = flag; #ifdef _LP64 iop->_file = fd; #else if (fd <= _FILE_FD_MAX) { SET_FILE(iop, fd); } else if (_file_set(iop, fd, type) != 0) { /* errno set by _file_set () */ iop->_flag = 0; /* release iop */ return (NULL); } #endif /* _LP64 */ return (iop); }
static void _process_emotion_commands(struct _App *app) { int cmd = _em_cmd_read(app); switch (cmd) { case EM_CMD_FILE_SET: _file_set(app); break; case EM_CMD_FILE_SET_DONE: _file_set_done(app); break; case EM_CMD_FILE_CLOSE: _file_close(app); break; case EM_CMD_PLAY: _play(app); break; case EM_CMD_STOP: _stop(app); break; case EM_CMD_POSITION_SET: _position_set(app); break; case EM_CMD_SPEED_SET: _speed_set(app); break; case EM_CMD_AUDIO_MUTE_SET: _mute_set(app); break; case EM_CMD_VOLUME_SET: _volume_set(app); break; case EM_CMD_AUDIO_TRACK_SET: _audio_track_set(app); break; case EM_CMD_VIDEO_TRACK_SET: _video_track_set(app); break; }; }
FILE * _endopen(const char *name, const char *type, FILE *iop, int largefile) { int oflag, fd, fflag, eflag, plusflag, xflag; const char *echr; if (iop == NULL) return (NULL); switch (type[0]) { default: errno = EINVAL; return (NULL); case 'r': oflag = O_RDONLY; fflag = _IOREAD; break; case 'w': oflag = O_WRONLY | O_TRUNC | O_CREAT; fflag = _IOWRT; break; case 'a': oflag = O_WRONLY | O_APPEND | O_CREAT; fflag = _IOWRT; break; } plusflag = 0; eflag = 0; xflag = 0; for (echr = type + 1; *echr != '\0'; echr++) { switch (*echr) { /* UNIX ignores 'b' and treats text and binary the same */ default: break; case '+': plusflag = 1; break; case 'e': eflag = 1; break; case 'x': xflag = 1; break; } } if (eflag) { /* Subsequent to a mode flag, 'e' indicates O_CLOEXEC */ oflag = oflag | O_CLOEXEC; } if (plusflag) { oflag = (oflag & ~(O_RDONLY | O_WRONLY)) | O_RDWR; fflag = _IORW; } if (xflag) { oflag |= O_EXCL; } /* select small or large file open based on flag */ if (largefile) { fd = open64(name, oflag, 0666); } else { fd = open(name, oflag, 0666); } if (fd < 0) return (NULL); /* As long as we make sure _flag stays != 0, we don't need to lock */ #ifdef _LP64 iop->_file = fd; iop->_flag = (iop->_flag & ~0377) | fflag; #else if (fd <= _FILE_FD_MAX) { SET_FILE(iop, fd); } else if (_file_set(iop, fd, type) != 0) { /* errno set in _file_set() */ (void) close(fd); return (NULL); } iop->_flag = fflag; #endif /* _LP64 */ if (oflag == (O_WRONLY | O_APPEND | O_CREAT)) { /* type == "a" */ if (lseek64(fd, (off64_t)0, SEEK_END) < (off64_t)0) { (void) close(fd); return (NULL); } } return (iop); }