Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from jgarzik/macos
Browse files Browse the repository at this point in the history
Macos - more support
  • Loading branch information
jgarzik authored Feb 25, 2024
2 parents 6ad8fea + 294fe14 commit 5d30733
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 1 deletion.
3 changes: 3 additions & 0 deletions comm/comm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* for setlinebuf(3), fgets_unlocked(3) */
#endif
#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <sys/types.h>
#include <limits.h>
Expand Down
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ AC_CHECK_LIB(argp, argp_parse, ARGP_LIB=-largp)

AC_DEFINE(_ISOC99_SOURCE, 1, [ISOC99 source])
AC_DEFINE(_POSIX_SOURCE, 1, [POSIX source])
AC_DEFINE(_DARWIN_C_SOURCE, 1, [Apple Darwin C source])
AC_DEFINE(_POSIX_C_SOURCE, 200809L, [POSIX C source])
AC_DEFINE(_XOPEN_SOURCE, 700, [X/Open source])
AC_DEFINE(_XOPEN_SOURCE_EXTENDED, 1, [X/open extended source])
Expand Down
3 changes: 3 additions & 0 deletions date/date.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include "posixutils-config.h"

#define _BSD_SOURCE
#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <stdlib.h>
#include <string>
Expand Down
44 changes: 44 additions & 0 deletions df/df.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#endif
#include "posixutils-config.h"

#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif
#define __STDC_FORMAT_MACROS 1

#include <sys/stat.h>
Expand All @@ -33,8 +36,14 @@
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#ifdef __linux__
#include <mntent.h>
#include <sys/vfs.h>
#elif __APPLE__
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
#endif
#include <paths.h>
#include <libpu.h>

Expand Down Expand Up @@ -95,6 +104,7 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state)
PU_OPT_END
}

#ifdef __linux__
static void push_mntent(struct mntent *me)
{
struct stat st;
Expand All @@ -112,9 +122,31 @@ static void push_mntent(struct mntent *me)

fslist.push_back(fl);
}
#endif

#ifdef __APPLE__
static void push_mntent(const struct statfs *sfs)
{
struct stat st;

FSListEnt fl;
fl.devname.assign(sfs->f_mntfromname);
fl.dir.assign(sfs->f_mntonname);

if (stat(fl.devname.c_str(), &st) == 0)
fl.dev = st.st_rdev;
else if (stat(fl.dir.c_str(), &st) == 0)
fl.dev = st.st_dev;
else
fl.dev = (dev_t) -1;

fslist.push_back(fl);
}
#endif

static int read_mntlist(void)
{
#ifdef __linux__
struct mntent *me;

FILE *f = setmntent(_PATH_MOUNTED, "r");
Expand All @@ -127,6 +159,18 @@ static int read_mntlist(void)
push_mntent(me);

endmntent(f);
#elif __APPLE__
struct statfs* mounts = NULL;
int n_mnt = getmntinfo(&mounts, MNT_WAIT);
if (n_mnt < 0) {
perror("getmntinfo");
return 1;
}

for (int i = 0; i < n_mnt; i++) {
push_mntent(&mounts[i]);
}
#endif

return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions getconf/getconf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#endif
#include "posixutils-config.h"

#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <unistd.h>
#include <string.h>
#include <stdio.h>
Expand Down
3 changes: 3 additions & 0 deletions grep/grep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* for strcasestr(3), fgets_unlocked(3) */
#endif
#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#define __STDC_FORMAT_MACROS 1

Expand Down
1 change: 1 addition & 0 deletions include/libpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define N_(String) String


#undef ALIGN
#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

Expand Down
4 changes: 4 additions & 0 deletions ipcrm/ipcrm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#endif
#include "posixutils-config.h"

#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <sys/types.h>
#include <stdlib.h>
#include <string.h>
Expand Down
3 changes: 3 additions & 0 deletions kill/kill.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <sys/types.h>
#include <unistd.h>
Expand Down
3 changes: 3 additions & 0 deletions renice/renice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
#error missing autoconf-generated config.h.
#endif
#include "posixutils-config.h"
#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <sys/types.h>
#include <sys/time.h>
Expand Down
3 changes: 3 additions & 0 deletions split/split.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* for O_DIRECTORY, fgets_unlocked(3) */
#endif
#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif
#define __STDC_FORMAT_MACROS 1

#include <sys/types.h>
Expand Down
4 changes: 4 additions & 0 deletions stty/stty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
#endif
#include "posixutils-config.h"

#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
Expand Down
3 changes: 3 additions & 0 deletions time/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include "posixutils-config.h"

#define _BSD_SOURCE /* for wait4(2) */
#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <sys/types.h>
#include <sys/time.h>
Expand Down
3 changes: 3 additions & 0 deletions what/what.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE /* for setlinebuf(3), fgets_unlocked(3) */
#endif
#ifdef __APPLE__
#define _DARWIN_C_SOURCE 1
#endif

#include <string.h>
#include <limits.h>
Expand Down

0 comments on commit 5d30733

Please sign in to comment.