[hackers] [sbase] apathmax || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Sat, 25 Jun 2011 18:27:03 +0200 (CEST)

changeset: 95:90c239c56e2b
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Sat Jun 25 17:26:44 2011 +0100
files: Makefile util.h util/agetcwd.c util/apathmax.c util/enmasse.c
description:
apathmax

diff -r 83c91ed2e467 -r 90c239c56e2b Makefile
--- a/Makefile Fri Jun 24 08:33:08 2011 +0100
+++ b/Makefile Sat Jun 25 17:26:44 2011 +0100
@@ -4,6 +4,7 @@
 LIB = \
         util/afgets.o \
         util/agetcwd.o \
+ util/apathmax.o \
         util/concat.o \
         util/enmasse.o \
         util/eprintf.o \
diff -r 83c91ed2e467 -r 90c239c56e2b util.h
--- a/util.h Fri Jun 24 08:33:08 2011 +0100
+++ b/util.h Sat Jun 25 17:26:44 2011 +0100
@@ -4,6 +4,7 @@
 
 char *agetcwd(void);
 void enmasse(int, char **, int (*)(const char *, const char *));
+void apathmax(char **, long *);
 void eprintf(const char *, ...);
 void enprintf(int, const char *, ...);
 long estrtol(const char *, int);
diff -r 83c91ed2e467 -r 90c239c56e2b util/agetcwd.c
--- a/util/agetcwd.c Fri Jun 24 08:33:08 2011 +0100
+++ b/util/agetcwd.c Sat Jun 25 17:26:44 2011 +0100
@@ -1,6 +1,4 @@
 /* See LICENSE file for copyright and license details. */
-#include <stdio.h>
-#include <stdlib.h>
 #include <unistd.h>
 #include "../util.h"
 
@@ -10,10 +8,7 @@
         char *buf;
         long size;
 
- if((size = pathconf(".", _PC_PATH_MAX)) == -1)
- size = BUFSIZ;
- if(!(buf = malloc(size)))
- eprintf("malloc:");
+ apathmax(&buf, &size);
         if(!getcwd(buf, size))
                 eprintf("getcwd:");
         return buf;
diff -r 83c91ed2e467 -r 90c239c56e2b util/apathmax.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/util/apathmax.c Sat Jun 25 17:26:44 2011 +0100
@@ -0,0 +1,24 @@
+/* See LICENSE file for copyright and license details. */
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include "../util.h"
+
+void
+apathmax(char **p, long *size)
+{
+#ifdef PATH_MAX
+ *size = PATH_MAX;
+#else
+ errno = 0;
+ if((*size = pathconf(".", _PC_PATH_MAX)) == -1) {
+ if(errno == 0)
+ *size = BUFSIZ;
+ else
+ eprintf("pathconf:");
+ }
+#endif
+ if(!(*p = malloc(*size)))
+ eprintf("malloc:");
+}
diff -r 83c91ed2e467 -r 90c239c56e2b util/enmasse.c
--- a/util/enmasse.c Fri Jun 24 08:33:08 2011 +0100
+++ b/util/enmasse.c Sat Jun 25 17:26:44 2011 +0100
@@ -24,10 +24,7 @@
         else
                 dir = (argc == 1) ? "." : argv[--argc];
 
- if((size = pathconf(dir, _PC_PATH_MAX)) == -1)
- size = BUFSIZ;
- if(!(buf = malloc(size)))
- eprintf("malloc:");
+ apathmax(&buf, &size);
         for(i = 0; i < argc; i++) {
                 if(snprintf(buf, size, "%s/%s", dir, basename(argv[i])) > size)
                         eprintf("%s/%s: filename too long\n", dir, basename(argv[i]));
Received on Sat Jun 25 2011 - 18:27:03 CEST

This archive was generated by hypermail 2.2.0 : Sat Jun 25 2011 - 18:36:05 CEST