attribute_compat_text_section _IO_old_file_attach (_IO_FILE *fp, int fd) { if (_IO_file_is_open (fp)) return NULL; fp->_fileno = fd; fp->_flags &= ~(_IO_NO_READS+_IO_NO_WRITES); fp->_flags |= _IO_DELETE_DONT_CLOSE; /* Get the current position of the file. */ /* We have to do that since that may be junk. */ fp->_old_offset = _IO_pos_BAD; if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_cur, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD && errno != ESPIPE) return NULL; return fp; }
attribute_compat_text_section _IO_old_file_fopen (_IO_FILE *fp, const char *filename, const char *mode) { int oflags = 0, omode; int read_write, fdesc; int oprot = 0666; if (_IO_file_is_open (fp)) return 0; switch (*mode++) { case 'r': omode = O_RDONLY; read_write = _IO_NO_WRITES; break; case 'w': omode = O_WRONLY; oflags = O_CREAT|O_TRUNC; read_write = _IO_NO_READS; break; case 'a': omode = O_WRONLY; oflags = O_CREAT|O_APPEND; read_write = _IO_NO_READS|_IO_IS_APPENDING; break; default: __set_errno (EINVAL); return NULL; } if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) { omode = O_RDWR; read_write &= _IO_IS_APPENDING; } fdesc = open (filename, omode|oflags, oprot); if (fdesc < 0) return NULL; fp->_fileno = fdesc; _IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING); if (read_write & _IO_IS_APPENDING) if (_IO_SEEKOFF (fp, (_IO_off_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD && errno != ESPIPE) return NULL; _IO_link_in ((struct _IO_FILE_plus *) fp); return fp; }
_IO_off64_t _IO_seekpos_unlocked (_IO_FILE *fp, _IO_off64_t pos, int mode) { /* If we have a backup buffer, get rid of it, since the __seekoff callback may not know to do the right thing about it. This may be over-kill, but it'll do for now. TODO */ if (_IO_fwide (fp, 0) <= 0) { if (_IO_have_backup (fp)) _IO_free_backup_area (fp); } else { if (_IO_have_wbackup (fp)) _IO_free_wbackup_area (fp); } return _IO_SEEKOFF (fp, pos, 0, mode); }
_IO_off64_t _IO_default_seekpos (_IO_FILE *fp, _IO_off64_t pos, int mode) { return _IO_SEEKOFF (fp, pos, 0, mode); }