libinstaller: Use SOURCE_DATE_EPOCH for synthesized modification time stamps
[syslinux.git] / libinstaller / syslxrw.c
blob86876e8c132bef7a457b6c70031dda28a4aea54b
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2010 Intel Corp. - All Rights Reserved
4 * Copyright 2015 Paulo Alcantara <pcacjr@zytor.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 * Boston MA 02111-1307, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <string.h>
17 #include <errno.h>
18 #include <fcntl.h>
19 #include <unistd.h>
21 #include "syslxrw.h"
23 static void die(const char *msg)
25 fputs(msg, stderr);
26 exit(1);
30 * read/write wrapper functions
32 ssize_t xpread(int fd, void *buf, size_t count, off_t offset)
34 char *bufp = (char *)buf;
35 ssize_t rv;
36 ssize_t done = 0;
38 while (count) {
39 rv = pread(fd, bufp, count, offset);
40 if (rv == 0) {
41 die("short read");
42 } else if (rv == -1) {
43 if (errno == EINTR) {
44 continue;
45 } else {
46 die(strerror(errno));
48 } else {
49 bufp += rv;
50 offset += rv;
51 done += rv;
52 count -= rv;
56 return done;
59 ssize_t xpwrite(int fd, const void *buf, size_t count, off_t offset)
61 const char *bufp = (const char *)buf;
62 ssize_t rv;
63 ssize_t done = 0;
65 while (count) {
66 rv = pwrite(fd, bufp, count, offset);
67 if (rv == 0) {
68 die("short write");
69 } else if (rv == -1) {
70 if (errno == EINTR) {
71 continue;
72 } else {
73 die(strerror(errno));
75 } else {
76 bufp += rv;
77 offset += rv;
78 done += rv;
79 count -= rv;
83 return done;