1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
11 FILE* FAST_FUNC fopen_or_warn(const char *path, const char *mode)
13 FILE *fp = fopen(path, mode);
15 bb_simple_perror_msg(path);
16 //errno = 0; /* why? */
21 FILE* FAST_FUNC fopen_for_read(const char *path)
23 return fopen(path, "r");
26 FILE* FAST_FUNC xfopen_for_read(const char *path)
28 return xfopen(path, "r");
31 FILE* FAST_FUNC fopen_for_write(const char *path)
33 return fopen(path, "w");
36 FILE* FAST_FUNC xfopen_for_write(const char *path)
38 return xfopen(path, "w");
41 static FILE* xfdopen_helper(unsigned fd_and_rw_bit)
43 FILE* fp = fdopen(fd_and_rw_bit >> 1, fd_and_rw_bit & 1 ? "w" : "r");
45 bb_die_memory_exhausted();
48 FILE* FAST_FUNC xfdopen_for_read(int fd)
50 return xfdopen_helper(fd << 1);
52 FILE* FAST_FUNC xfdopen_for_write(int fd)
54 return xfdopen_helper((fd << 1) + 1);