aboutsummaryrefslogtreecommitdiff
blob: 2e405c6864abcd78319d1cd6063981807d500655 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * sb_open.c
 *
 * IO functions.
 *
 * Copyright 1999-2008 Gentoo Foundation
 * Licensed under the GPL-2
 */

#include "headers.h"
#include "sbutil.h"

static int (*sbio_open)(const char *, int, mode_t) = (void *)open;


void sb_set_open(void *new_open)
{
	if (!check_ptr(new_open))
		return;

	sbio_open = new_open;
}

/* General purpose function to _reliably_ open a file
 *
 * Returns the file descriptor or -1 on error (and errno set)
 */

int sb_open(const char *path, int flags, mode_t mode)
{
	int fd;

	do {
		fd = sbio_open(path, flags, mode);
	} while ((-1 == fd) && (EINTR == errno));

	if ((-1 != fd) && (0 != errno))
		/* Do not trigger debugging */
		errno = 0;

	if (-1 == fd)
		DBG_MSG("Failed to open file '%s'!\n", path);

	return fd;
}