blind

suckless command-line video editing utility
git clone git://git.suckless.org/blind
Log | Files | Refs | README | LICENSE

efunc.h (1576B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <sys/wait.h>
      3 #include <unistd.h>
      4 
      5 #define eexecvp(F, ...) (execvp(F, __VA_ARGS__), eprintf("exec %s:", F))
      6 #define eexeclp(F, ...) (execlp(F, __VA_ARGS__), eprintf("exec %s:", F))
      7 
      8 static inline void
      9 epipe(int fds[2])
     10 {
     11 	if (pipe(fds))
     12 		eprintf("pipe:");
     13 }
     14 
     15 static inline pid_t
     16 efork(void)
     17 {
     18 	pid_t ret = fork();
     19 	if (ret < 0)
     20 		eprintf("fork:");
     21 	return ret;
     22 }
     23 
     24 static inline void
     25 edup2(int old, int new)
     26 {
     27 	if (dup2(old, new) < 0)
     28 		eprintf("dup2:");
     29 }
     30 
     31 static inline int
     32 edup(int fd)
     33 {
     34 	int ret = dup(fd);
     35 	if (ret < 0)
     36 		eprintf("dup:");
     37 	return ret;
     38 }
     39 
     40 static inline pid_t
     41 ewaitpid(pid_t pid, int *status, int flags)
     42 {
     43 	pid_t ret = waitpid(pid, status, flags);
     44 	if (ret < 0)
     45 		eprintf("waitpid:");
     46 	return ret;
     47 }
     48 
     49 static inline size_t
     50 eread(int fd, void *buf, size_t n, const char *fname)
     51 {
     52 	ssize_t ret = read(fd, buf, n);
     53 	if (ret < 0)
     54 		eprintf("read %s:", fname);
     55 	return (size_t)ret;
     56 }
     57 
     58 static inline size_t
     59 epread(int fd, void *buf, size_t n, off_t off, const char *fname)
     60 {
     61 	ssize_t ret = pread(fd, buf, n, off);
     62 	if (ret < 0)
     63 		eprintf("pread %s:", fname);
     64 	return (size_t)ret;
     65 }
     66 
     67 static inline size_t
     68 ewrite(int fd, void *buf, size_t n, const char *fname)
     69 {
     70 	ssize_t ret = write(fd, buf, n);
     71 	if (ret < 0) {
     72 		if (errno == ECONNRESET)
     73 			raise(SIGPIPE);
     74 		eprintf("write %s:", fname);
     75 	}
     76 	return (size_t)ret;
     77 }
     78 
     79 static inline off_t
     80 elseek(int fd, off_t offset, int whence, const char *fname)
     81 {
     82 	off_t ret = lseek(fd, offset, whence);
     83 	if (ret < 0)
     84 		eprintf("lseek %s:", fname);
     85 	return ret;
     86 }