OS X support

pull/1/head
Sean 8 years ago
parent f82dddeeb9
commit 1bacdbc034

@ -41,6 +41,9 @@ endif
ifeq ($(USE_THREADS)-$(SYSTEM),yes-freebsd) ifeq ($(USE_THREADS)-$(SYSTEM),yes-freebsd)
CFLAGS += -DUSE_THREADS=1 -D_REENTRANT -pthread CFLAGS += -DUSE_THREADS=1 -D_REENTRANT -pthread
endif endif
ifeq ($(USE_THREADS)-$(SYSTEM),yes-darwin)
CFLAGS += -DUSE_THREADS=1 -D_REENTRANT -pthread
endif
# OpenSSL yes/no # OpenSSL yes/no

24
ls.c

@ -62,7 +62,7 @@ xgetpwuid(uid_t uid)
next++; next++;
if (CACHE_SIZE == next) next = 0; if (CACHE_SIZE == next) next = 0;
if (used < CACHE_SIZE) used++; if (used < CACHE_SIZE) used++;
return pw ? pw->pw_name : NULL; return pw ? pw->pw_name : NULL;
} }
@ -100,7 +100,7 @@ xgetgrgid(gid_t gid)
next++; next++;
if (CACHE_SIZE == next) next = 0; if (CACHE_SIZE == next) next = 0;
if (used < CACHE_SIZE) used++; if (used < CACHE_SIZE) used++;
return gr ? gr->gr_name : NULL; return gr ? gr->gr_name : NULL;
} }
@ -160,7 +160,7 @@ quote(unsigned char *path, int maxlength)
return buf; return buf;
} }
#if !defined(__FreeBSD__) && !defined(__OpenBSD__) #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__)
static void strmode(mode_t mode, char *dest) static void strmode(mode_t mode, char *dest)
{ {
static const char *rwx[] = { static const char *rwx[] = {
@ -177,7 +177,7 @@ static void strmode(mode_t mode, char *dest)
case S_IFSOCK: dest[0] = '='; break; case S_IFSOCK: dest[0] = '='; break;
default: dest[0] = '?'; break; default: dest[0] = '?'; break;
} }
/* access rights */ /* access rights */
sprintf(dest+1,"%s%s%s", sprintf(dest+1,"%s%s%s",
rwx[(mode >> 6) & 0x7], rwx[(mode >> 6) & 0x7],
@ -186,7 +186,7 @@ static void strmode(mode_t mode, char *dest)
} }
#endif #endif
static char* static char*
ls(time_t now, char *hostname, char *filename, char *path, int *length) ls(time_t now, char *hostname, char *filename, char *path, int *length)
{ {
DIR *dir; DIR *dir;
@ -237,7 +237,7 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length)
count--; count--;
continue; continue;
} }
files[count]->r = 0; files[count]->r = 0;
if (S_ISDIR(files[count]->s.st_mode) || if (S_ISDIR(files[count]->s.st_mode) ||
S_ISREG(files[count]->s.st_mode)) { S_ISREG(files[count]->s.st_mode)) {
@ -252,7 +252,7 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length)
} }
} }
closedir(dir); closedir(dir);
/* sort */ /* sort */
if (count) if (count)
qsort(files,count,sizeof(struct myfile*),compare_files); qsort(files,count,sizeof(struct myfile*),compare_files);
@ -314,21 +314,21 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length)
len += 10; len += 10;
buf[len++] = ' '; buf[len++] = ' ';
buf[len++] = ' '; buf[len++] = ' ';
/* user */ /* user */
pw = xgetpwuid(files[i]->s.st_uid); pw = xgetpwuid(files[i]->s.st_uid);
if (NULL != pw) if (NULL != pw)
len += sprintf(buf+len,"%-8.8s ",pw); len += sprintf(buf+len,"%-8.8s ",pw);
else else
len += sprintf(buf+len,"%8d ",(int)files[i]->s.st_uid); len += sprintf(buf+len,"%8d ",(int)files[i]->s.st_uid);
/* group */ /* group */
gr = xgetgrgid(files[i]->s.st_gid); gr = xgetgrgid(files[i]->s.st_gid);
if (NULL != gr) if (NULL != gr)
len += sprintf(buf+len,"%-8.8s ",gr); len += sprintf(buf+len,"%-8.8s ",gr);
else else
len += sprintf(buf+len,"%8d ",(int)files[i]->s.st_gid); len += sprintf(buf+len,"%8d ",(int)files[i]->s.st_gid);
/* mtime */ /* mtime */
if (now - files[i]->s.st_mtime > 60*60*24*30*6) if (now - files[i]->s.st_mtime > 60*60*24*30*6)
len += strftime(buf+len,255,"%b %d %Y ", len += strftime(buf+len,255,"%b %d %Y ",
@ -336,7 +336,7 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length)
else else
len += strftime(buf+len,255,"%b %d %H:%M ", len += strftime(buf+len,255,"%b %d %H:%M ",
gmtime(&files[i]->s.st_mtime)); gmtime(&files[i]->s.st_mtime));
/* size */ /* size */
if (S_ISDIR(files[i]->s.st_mode)) { if (S_ISDIR(files[i]->s.st_mode)) {
len += sprintf(buf+len," &lt;DIR&gt; "); len += sprintf(buf+len," &lt;DIR&gt; ");
@ -358,7 +358,7 @@ ls(time_t now, char *hostname, char *filename, char *path, int *length)
len += sprintf(buf+len,"%4d TB ", len += sprintf(buf+len,"%4d TB ",
(int)(files[i]->s.st_size>>40)); (int)(files[i]->s.st_size>>40));
} }
/* filename */ /* filename */
if (files[i]->r) { if (files[i]->r) {
len += sprintf(buf+len,"<a href=\"%s%s\">%s</a>\n", len += sprintf(buf+len,"<a href=\"%s%s\">%s</a>\n",

@ -132,7 +132,11 @@ config: Make.config
@true @true
Make.config: $(srcdir)/GNUmakefile Make.config: $(srcdir)/GNUmakefile
@echo -e "$(make-config-q)" > $@ ifeq ($(UNAME_S),Darwin)
@echo "$(make-config-q)" > $@
else
@echo -e "$(make-config-q)" > $@
endif
@echo @echo
@echo "Make.config written, edit if needed" @echo "Make.config written, edit if needed"
@echo @echo

Loading…
Cancel
Save