diff include/jeffpc/io.h @ 814:be934c5f8a42

io: add write_file_at Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 29 Aug 2020 12:00:28 -0400
parents 1b1a7ac50c23
children a445315f2016
line wrap: on
line diff
--- a/include/jeffpc/io.h	Tue Aug 25 19:57:25 2020 -0400
+++ b/include/jeffpc/io.h	Sat Aug 29 12:00:28 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2011-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -40,7 +40,8 @@
 extern int xpwrite(int fd, const void *buf, size_t nbyte, off_t off);
 
 extern char *read_file_common(int dirfd, const char *fname, struct stat *sb);
-extern int write_file(const char *fname, const char *data, size_t len);
+extern int write_file_at(int dirfd, const char *fname, const char *data,
+			 size_t len);
 
 static inline int xwrite_str(int fd, const char *s)
 {
@@ -69,6 +70,11 @@
 	return ret;
 }
 
+static inline int write_file(const char *fname, const void *data, size_t len)
+{
+	return write_file_at(AT_FDCWD, fname, data, len);
+}
+
 static inline int xopen(const char *fname, int flags, mode_t mode)
 {
 	int fd;