Merge bruno-penguin-1 into vudu_moca2
diff --git a/date.c b/date.c
index ae9282f..467e1e4 100644
--- a/date.c
+++ b/date.c
@@ -48,18 +48,39 @@
#endif
}
+static void settime_fmt(char *s, const char *fmt) {
+ struct tm tm;
+ struct timeval tv;
+
+ memset(&tm, 0, sizeof(tm));
+ if (strptime(s, fmt, &tm) == NULL) {
+ fprintf(stderr, "Unable to parse date '%s' as format '%s'\n", s, fmt);
+ exit(1);
+ }
+
+ tv.tv_sec = mktime(&tm);
+ tv.tv_usec = 0;
+ if (settimeofday(&tv, NULL)) {
+ char buf[80];
+ snprintf(buf, sizeof(buf), "settimeofday(%ld)", tv.tv_sec);
+ perror(buf);
+ exit(1);
+ }
+}
+
int date_main(int argc, char *argv[])
{
- int c;
+ int c;
int res;
- struct tm tm;
- time_t t;
- struct timeval tv;
+ struct tm tm;
+ time_t t;
+ struct timeval tv;
struct timespec ts;
- char strbuf[260];
+ char strbuf[260];
int fd;
int useutc = 0;
+ void *settime_arg = NULL;
tzset();
@@ -72,7 +93,7 @@
useutc = 1;
break;
case 's':
- settime(optarg);
+ settime_arg = optarg;
break;
case '?':
fprintf(stderr, "%s: invalid option -%c\n",
@@ -86,7 +107,13 @@
}
int hasfmt = argc == optind + 1 && argv[optind][0] == '+';
- if(optind == argc || hasfmt) {
+ if (settime_arg) {
+ if (hasfmt) {
+ settime_fmt(settime_arg, argv[optind] + 1);
+ } else{
+ settime(settime_arg);
+ }
+ } else if(optind == argc || hasfmt) {
char buf[2000];
time(&t);
if (useutc) {
diff --git a/ls.c b/ls.c
index 4990ed9..c9ff40f 100644
--- a/ls.c
+++ b/ls.c
@@ -257,22 +257,13 @@
return 0;
}
-static int listfile_long(const char *path, int flags)
+static int listfile_long(const char *path, const char *filename, int flags)
{
struct stat s;
char date[32];
char mode[16];
char user[16];
char group[16];
- const char *name;
-
- /* name is anything after the final '/', or the whole path if none*/
- name = strrchr(path, '/');
- if(name == 0) {
- name = path;
- } else {
- name++;
- }
if(lstat(path, &s) < 0) {
return -1;
@@ -291,14 +282,14 @@
switch(s.st_mode & S_IFMT) {
case S_IFBLK:
case S_IFCHR:
- printf("%s %-8s %-8s %3d, %3d %s %s\n",
+ printf("%s %-8s %-8s %5d, %3d %s %s\n",
mode, user, group,
(int) MAJOR(s.st_rdev), (int) MINOR(s.st_rdev),
- date, name);
+ date, filename);
break;
case S_IFREG:
- printf("%s %-8s %-8s %12lld %s %s\n",
- mode, user, group, s.st_size, date, name);
+ printf("%s %-8s %-8s %10lld %s %s\n",
+ mode, user, group, s.st_size, date, filename);
break;
case S_IFLNK: {
char linkto[256];
@@ -316,13 +307,13 @@
linkto[len] = 0;
}
- printf("%s %-8s %-8s %s %s -> %s\n",
- mode, user, group, date, name, linkto);
+ printf("%s %-8s %-8s %s %s -> %s\n",
+ mode, user, group, date, filename, linkto);
break;
}
default:
- printf("%s %-8s %-8s %s %s\n",
- mode, user, group, date, name);
+ printf("%s %-8s %-8s %s %s\n",
+ mode, user, group, date, filename);
}
return 0;
@@ -346,7 +337,7 @@
}
if ((flags & LIST_LONG) != 0) {
- return listfile_long(pathname, flags);
+ return listfile_long(pathname, filename, flags);
} else /*((flags & LIST_SIZE) != 0)*/ {
return listfile_size(pathname, filename, flags);
}