Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bring in OPEN/CLOSE macros and refactor into a switch

  • Loading branch information...
commit a61e178f57f0cf141edd6c7e9e32a4f72afc1ccb 1 parent f01e268
@falconindy authored
Showing with 14 additions and 11 deletions.
  1. +11 −11 curl.c
  2. +3 −0  util.h
View
22 curl.c
@@ -207,18 +207,18 @@ long aur_upload(const char *taurball) {
struct write_result response = { NULL, 0 };
int fd;
- do {
- fd = open(taurball, O_DIRECTORY|O_RDONLY);
- } while (errno == EINTR);
- if (fd > 0) {
- fprintf(stderr, "error: target is not a file: %s\n", taurball);
- close(fd);
- return ret;
- } else if (errno != ENOTDIR) {
- fprintf(stderr, "error: failed to read `%s': %s\n", taurball, strerror(errno));
- return ret;
+ OPEN(fd, taurball, O_DIRECTORY|O_RDONLY);
+ switch (errno) {
+ case ENOTDIR:
+ break;
+ case 0:
+ fprintf(stderr, "error: target is not a file: %s\n", taurball);
+ CLOSE(fd);
+ return ret;
+ default:
+ fprintf(stderr, "error: failed to read `%s': %s\n", taurball, strerror(errno));
+ return ret;
}
- close(fd);
display_name = strrchr(taurball, '/');
if (display_name) {
View
3  util.h
@@ -34,6 +34,9 @@
#define MALLOC(p, s, action) do { p = calloc(1, s); if(!p) { ALLOC_FAIL(s); action; } } while(0)
#define FREE(x) do { free((void*)x); x = NULL; } while(0)
+#define OPEN(fd, path, flags) do { fd = open(path, flags); } while(fd == -1 && errno == EINTR)
+#define CLOSE(fd) do { int rc; do { rc = close(fd); } while(rc == -1 && errno == EINTR); } while(0)
+
void debug(const char*, ...);
char *read_stdin(const char*, size_t, int);
size_t strtrim(char*);
Please sign in to comment.
Something went wrong with that request. Please try again.