comparison 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
comparison
equal deleted inserted replaced
813:d563f6d72c1e 814:be934c5f8a42
1 /* 1 /*
2 * Copyright (c) 2011-2018 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> 2 * Copyright (c) 2011-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
3 * 3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal 5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights 6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
38 extern int xwrite(int fd, const void *buf, size_t nbyte); 38 extern int xwrite(int fd, const void *buf, size_t nbyte);
39 extern int xpread(int fd, void *buf, size_t nbyte, off_t off); 39 extern int xpread(int fd, void *buf, size_t nbyte, off_t off);
40 extern int xpwrite(int fd, const void *buf, size_t nbyte, off_t off); 40 extern int xpwrite(int fd, const void *buf, size_t nbyte, off_t off);
41 41
42 extern char *read_file_common(int dirfd, const char *fname, struct stat *sb); 42 extern char *read_file_common(int dirfd, const char *fname, struct stat *sb);
43 extern int write_file(const char *fname, const char *data, size_t len); 43 extern int write_file_at(int dirfd, const char *fname, const char *data,
44 size_t len);
44 45
45 static inline int xwrite_str(int fd, const char *s) 46 static inline int xwrite_str(int fd, const char *s)
46 { 47 {
47 return xwrite(fd, s, strlen(s)); 48 return xwrite(fd, s, strlen(s));
48 } 49 }
65 ret = read_file_common(AT_FDCWD, fname, &sb); 66 ret = read_file_common(AT_FDCWD, fname, &sb);
66 if (!IS_ERR(ret)) 67 if (!IS_ERR(ret))
67 *len = sb.st_size; 68 *len = sb.st_size;
68 69
69 return ret; 70 return ret;
71 }
72
73 static inline int write_file(const char *fname, const void *data, size_t len)
74 {
75 return write_file_at(AT_FDCWD, fname, data, len);
70 } 76 }
71 77
72 static inline int xopen(const char *fname, int flags, mode_t mode) 78 static inline int xopen(const char *fname, int flags, mode_t mode)
73 { 79 {
74 int fd; 80 int fd;