om

om - the most recently modified file in a directory
git clone git://git.larryhynes.net/om
Log | Files | Refs | README

commit 246e0b61585c93b0e8a9901dbd9ad3c7a3d515b7
parent b9fafe616caf9a982f374fbcfba538693ed588d1
Author: Larry Hynes <larry@larryhynes.com>
Date:   Mon, 26 Jun 2017 17:11:13 +0100

Use PATH_MAX instead of #defining MAX_LEN
- remove #define for MAX_LEN
- just use PATH_MAX from <limits.h>
- tested on Darwin, Linux and OpenBSD

Diffstat:
om.c | 11+++++------
1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/om.c b/om.c @@ -2,12 +2,11 @@ #include <dirent.h> #include <err.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#define MAX_LEN 1024 - char *dir; /* Test if the argument is a directory */ @@ -25,8 +24,8 @@ isadir() } } -char buf[MAX_LEN]; -char rcnt[MAX_LEN]; +char buf[PATH_MAX]; +char rcnt[PATH_MAX]; void om(const char* dir, char* rcnt) @@ -40,10 +39,10 @@ om(const char* dir, char* rcnt) if (dirp != NULL) { while ((ent = readdir(dirp)) != NULL) { if (ent->d_type == DT_REG) { - snprintf(buf, MAX_LEN, "%s/%s", dir, ent->d_name); + snprintf(buf, PATH_MAX, "%s/%s", dir, ent->d_name); stat(buf, &sb); if (sb.st_mtime > mtime) { - snprintf(rcnt, MAX_LEN, "%s/%s", dir, ent->d_name ); + snprintf(rcnt, PATH_MAX, "%s/%s", dir, ent->d_name ); mtime = sb.st_mtime; } }