diff options
Diffstat (limited to 'tools/perf/util/wrapper.c')
| -rw-r--r-- | tools/perf/util/wrapper.c | 72 |
1 files changed, 1 insertions, 71 deletions
diff --git a/tools/perf/util/wrapper.c b/tools/perf/util/wrapper.c index bf44ca85d23b..c4ced7c1251d 100644 --- a/tools/perf/util/wrapper.c +++ b/tools/perf/util/wrapper.c | |||
| @@ -48,7 +48,7 @@ void *xmalloc(size_t size) | |||
| 48 | * and returns a pointer to the allocated memory. If the allocation fails, | 48 | * and returns a pointer to the allocated memory. If the allocation fails, |
| 49 | * the program dies. | 49 | * the program dies. |
| 50 | */ | 50 | */ |
| 51 | void *xmemdupz(const void *data, size_t len) | 51 | static void *xmemdupz(const void *data, size_t len) |
| 52 | { | 52 | { |
| 53 | char *p = xmalloc(len + 1); | 53 | char *p = xmalloc(len + 1); |
| 54 | memcpy(p, data, len); | 54 | memcpy(p, data, len); |
| @@ -78,73 +78,3 @@ void *xrealloc(void *ptr, size_t size) | |||
| 78 | } | 78 | } |
| 79 | return ret; | 79 | return ret; |
| 80 | } | 80 | } |
| 81 | |||
| 82 | /* | ||
| 83 | * xread() is the same a read(), but it automatically restarts read() | ||
| 84 | * operations with a recoverable error (EAGAIN and EINTR). xread() | ||
| 85 | * DOES NOT GUARANTEE that "len" bytes is read even if the data is available. | ||
| 86 | */ | ||
| 87 | static ssize_t xread(int fd, void *buf, size_t len) | ||
| 88 | { | ||
| 89 | ssize_t nr; | ||
| 90 | while (1) { | ||
| 91 | nr = read(fd, buf, len); | ||
| 92 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
| 93 | continue; | ||
| 94 | return nr; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | /* | ||
| 99 | * xwrite() is the same a write(), but it automatically restarts write() | ||
| 100 | * operations with a recoverable error (EAGAIN and EINTR). xwrite() DOES NOT | ||
| 101 | * GUARANTEE that "len" bytes is written even if the operation is successful. | ||
| 102 | */ | ||
| 103 | static ssize_t xwrite(int fd, const void *buf, size_t len) | ||
| 104 | { | ||
| 105 | ssize_t nr; | ||
| 106 | while (1) { | ||
| 107 | nr = write(fd, buf, len); | ||
| 108 | if ((nr < 0) && (errno == EAGAIN || errno == EINTR)) | ||
| 109 | continue; | ||
| 110 | return nr; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | ssize_t read_in_full(int fd, void *buf, size_t count) | ||
| 115 | { | ||
| 116 | char *p = buf; | ||
| 117 | ssize_t total = 0; | ||
| 118 | |||
| 119 | while (count > 0) { | ||
| 120 | ssize_t loaded = xread(fd, p, count); | ||
| 121 | if (loaded <= 0) | ||
| 122 | return total ? total : loaded; | ||
| 123 | count -= loaded; | ||
| 124 | p += loaded; | ||
| 125 | total += loaded; | ||
| 126 | } | ||
| 127 | |||
| 128 | return total; | ||
| 129 | } | ||
| 130 | |||
| 131 | ssize_t write_in_full(int fd, const void *buf, size_t count) | ||
| 132 | { | ||
| 133 | const char *p = buf; | ||
| 134 | ssize_t total = 0; | ||
| 135 | |||
| 136 | while (count > 0) { | ||
| 137 | ssize_t written = xwrite(fd, p, count); | ||
| 138 | if (written < 0) | ||
| 139 | return -1; | ||
| 140 | if (!written) { | ||
| 141 | errno = ENOSPC; | ||
| 142 | return -1; | ||
| 143 | } | ||
| 144 | count -= written; | ||
| 145 | p += written; | ||
| 146 | total += written; | ||
| 147 | } | ||
| 148 | |||
| 149 | return total; | ||
| 150 | } | ||
