Example #1
0
FILE *fdopen(int fd, const char *mode)
{
    int flags = __parse_open_mode(mode);
    int oldflags;

    if (fcntl(fd, F_GETFL, &oldflags))
        return NULL;

    oldflags = (oldflags & ~O_APPEND) | (flags & O_APPEND);
    if (fcntl(fd, F_SETFL, &oldflags))
        return NULL;

    return __fxopen(fd, flags, 0);
}
Example #2
0
FILE *fopen(const char *file, const char *mode)
{
	int flags = __parse_open_mode(mode);
	int fd, err;
	FILE *f;

	fd = open(file, flags, 0666);
	if (fd < 0)
		return NULL;

	f = fdopen(fd, mode);
	if (!f) {
		err = errno;
		close(fd);
		errno = err;
	}
	return f;
}