Message-ID: <35957D94.7694@teleline.es> Date: Sun, 28 Jun 1998 01:17:40 +0200 From: Mariano Alvarez Fernández Reply-To: malfer AT teleline DOT es Organization: teleline.es MIME-Version: 1.0 To: djgpp AT delorie DOT com CC: tla AT pac DOT nl Subject: Re: _fsopen Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk tla wrote: >how can i open a file with file-sharing.... >usually it's _fsopen, but it's not in libc. >or am i terrible mistaken? _fsopen do not exists in libc, I don't know why. But I needed it and I built it from fopen routine. Here it is. It work :-) /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */ /* _fsopen. This is fopen modified by M.Alvarez 1998 */ #include #include #include #include #include #include #include #include FILE * _fsopen(const char *file, const char *mode, int shmode) { FILE *f; int fd, rw, oflags = 0; char tbchar; if (file == 0) return 0; if (mode == 0) return 0; f = __alloc_file(); if (f == NULL) return NULL; rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+')); switch (*mode) { case 'a': oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY); break; case 'r': oflags = rw ? O_RDWR : O_RDONLY; break; case 'w': oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY); break; default: return (NULL); } if (mode[1] == '+') tbchar = mode[2]; else tbchar = mode[1]; if (tbchar == 't') oflags |= O_TEXT; else if (tbchar == 'b') oflags |= O_BINARY; else oflags |= (_fmode & (O_TEXT|O_BINARY)); oflags |= shmode; fd = open(file, oflags, 0666); if (fd < 0) return NULL; if (*mode == 'a') lseek(fd, 0, SEEK_END); f->_cnt = 0; f->_file = fd; f->_bufsiz = 0; if (rw) f->_flag = _IORW; else if (*mode == 'r') f->_flag = _IOREAD; else f->_flag = _IOWRT; f->_base = f->_ptr = NULL; return f; }