Some style fixes
This commit is contained in:
parent
ae2ac05ced
commit
0a6bb9ce08
|
@ -13,14 +13,15 @@
|
||||||
|
|
||||||
#define HANDLE_ERROR(msg) \
|
#define HANDLE_ERROR(msg) \
|
||||||
do { \
|
do { \
|
||||||
perror(msg); exit(EXIT_FAILURE); \
|
perror(msg); \
|
||||||
|
exit(EXIT_FAILURE); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TEMP_FAILURE_RETRY(var, expression) \
|
#define TEMP_FAILURE_RETRY(var, expression) \
|
||||||
do { \
|
do { \
|
||||||
long int __result; \
|
ptrdiff_t __result; \
|
||||||
do { \
|
do { \
|
||||||
__result = (long int) (expression); \
|
__result = (expression); \
|
||||||
} while (__result == -1L && errno == EINTR); \
|
} while (__result == -1L && errno == EINTR); \
|
||||||
var = __result; \
|
var = __result; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -56,7 +57,8 @@ void do_write(int sd, const char *raw, size_t len) {
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
int sd = -1;
|
int sd = -1;
|
||||||
ptrdiff_t i;
|
int i;
|
||||||
|
ptrdiff_t read_size;
|
||||||
struct sockaddr_un server;
|
struct sockaddr_un server;
|
||||||
char address[ADDRESS_SIZE];
|
char address[ADDRESS_SIZE];
|
||||||
const char eof[2] = "\0\0";
|
const char eof[2] = "\0\0";
|
||||||
|
@ -67,7 +69,8 @@ int main(int argc, char *argv[]) {
|
||||||
char **envp;
|
char **envp;
|
||||||
|
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("Must provide at least one argument.\n"); return EXIT_FAILURE;
|
printf("Must provide at least one argument.\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(address, ADDRESS_SIZE, ADDRESS_TEMPLATE, getuid());
|
snprintf(address, ADDRESS_SIZE, ADDRESS_TEMPLATE, getuid());
|
||||||
|
@ -113,20 +116,20 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
do_write(sd, eof, 2);
|
do_write(sd, eof, 2);
|
||||||
|
|
||||||
i = -1;
|
read_size = -1;
|
||||||
while (i != 0) {
|
while (read_size != 0) {
|
||||||
TEMP_FAILURE_RETRY(i, read(sd, buf, BUF_SIZE));
|
TEMP_FAILURE_RETRY(read_size, read(sd, buf, BUF_SIZE));
|
||||||
if (i == -1) {
|
if (read_size == -1) {
|
||||||
close(sd);
|
close(sd);
|
||||||
HANDLE_ERROR("read() failed");
|
HANDLE_ERROR("read() failed");
|
||||||
} else if (i > 0) {
|
} else if (read_size > 0) {
|
||||||
ptrdiff_t written = 0;
|
ptrdiff_t written = 0;
|
||||||
const char *bufp = &(buf[0]);
|
const char *bufp = &(buf[0]);
|
||||||
while (written < i) {
|
while (written < read_size) {
|
||||||
written = write(STDOUT_FILENO, buf, (size_t) i);
|
written = write(STDOUT_FILENO, buf, (size_t) read_size);
|
||||||
if (written >= 0) {
|
if (written >= 0) {
|
||||||
bufp += written;
|
bufp += written;
|
||||||
i -= written;
|
read_size -= written;
|
||||||
written = 0;
|
written = 0;
|
||||||
} else {
|
} else {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
Loading…
Reference in New Issue