* Copyright (C) 2006 Rob Landley
* Copyright (C) 2006 Denys Vlasenko
*
- * Licensed under GPL version 2, see file LICENSE in this tarball for details.
+ * Licensed under GPLv2, see file LICENSE in this source tree.
*/
/* We need to have separate xfuncs.c and xfuncs_printf.c because
return ret;
}
-// Die if we can't open an existing file and return a fd.
+// Die if we can't open a file and return a fd.
int FAST_FUNC xopen(const char *pathname, int flags)
{
return xopen3(pathname, flags, 0666);
return off;
}
+int FAST_FUNC xmkstemp(char *template)
+{
+ int fd = mkstemp(template);
+ if (fd < 0)
+ bb_perror_msg_and_die("can't create temp file '%s'", template);
+ return fd;
+}
+
// Die with supplied filename if this FILE* has ferror set.
void FAST_FUNC die_if_ferror(FILE *fp, const char *fn)
{
bb_perror_msg_and_die("can't stat '%s'", name);
}
+void FAST_FUNC xfstat(int fd, struct stat *stat_buf, const char *errmsg)
+{
+ /* errmsg is usually a file name, but not always:
+ * xfstat may be called in a spot where file name is no longer
+ * available, and caller may give e.g. "can't stat input file" string.
+ */
+ if (fstat(fd, stat_buf))
+ bb_simple_perror_msg_and_die(errmsg);
+}
+
// selinux_or_die() - die if SELinux is disabled.
void FAST_FUNC selinux_or_die(void)
{