unix/fiss

lib/libutil.old/openwrite.c in master
Repositories | Summary | Log | Files | LICENSE

openwrite.c (313B) download


 1#include "open.h"
 2
 3#include <unistd.h>
 4
 5int openwrite(const char* path, i32 oflags, mode_t mode, const void* buffer, ssize_t size) {
 6	int fd;
 7
 8	if ((fd = open(path, O_WRONLY | O_CREAT | oflags, mode)) == -1)
 9		return -1;
10
11	if (write(fd, buffer, size) != size) {
12		close(fd);
13		return -1;
14	}
15
16	return close(fd);
17}