summaryrefslogtreecommitdiff
path: root/com32/rosh
diff options
context:
space:
mode:
authorGene Cumm <gene.cumm@gmail.com>2011-01-31 09:05:59 -0500
committerGene Cumm <gene.cumm@gmail.com>2011-01-31 09:05:59 -0500
commit28f3eaaec3196f1b29f460e7c2bf47e2198c3759 (patch)
treeefc7655be068538fe1dd4a0a1f6ef8e1132c2d35 /com32/rosh
parent57b61307e8a1a2c773a8b3fa2621af0d4aa93819 (diff)
downloadsyslinux-28f3eaaec3196f1b29f460e7c2bf47e2198c3759.tar.gz
rosh: 2 bug fixes; more debug code
This fixes two issues when doing "ls -l"; directory entries with a directory argument were not qualified; stat() checked 1, not -1
Diffstat (limited to 'com32/rosh')
-rw-r--r--com32/rosh/rosh.c43
-rw-r--r--com32/rosh/rosh.h9
2 files changed, 33 insertions, 19 deletions
diff --git a/com32/rosh/rosh.c b/com32/rosh/rosh.c
index 12e09995..0581087e 100644
--- a/com32/rosh/rosh.c
+++ b/com32/rosh/rosh.c
@@ -1,6 +1,6 @@
/* ----------------------------------------------------------------------- *
*
- * Copyright 2008-2010 Gene Cumm - All Rights Reserved
+ * Copyright 2008-2011 Gene Cumm - All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -43,7 +43,7 @@
#define APP_NAME "rosh"
#define APP_AUTHOR "Gene Cumm"
#define APP_YEAR "2010"
-#define APP_VER "beta-b089"
+#define APP_VER "beta-b090"
/* Print version information to stdout
*/
@@ -576,26 +576,32 @@ int rosh_ls_de_size(const char *filestr, struct dirent *de)
* filestr directory name of directory entry
* de directory entry
*/
-int rosh_ls_de_size_mode(struct dirent *de, mode_t * st_mode)
+int rosh_ls_de_size_mode(const char *filestr, struct dirent *de, mode_t * st_mode)
{
int de_size;
-// char filestr2[ROSH_PATH_SZ];
-// int file2pos;
+ char filestr2[ROSH_PATH_SZ];
+ int file2pos;
struct stat fdstat;
int status;
-/* filestr2[0] = 0;
- file2pos = -1;*/
- fdstat.st_size = 0;
- fdstat.st_mode = 0;
-/* if (filestr) {
+ filestr2[0] = 0;
+ file2pos = -1;
+ memset(&fdstat, 0, sizeof fdstat);
+ ROSH_DEBUG2("ls:dsm(%s, %s) ", filestr, de->d_name);
+ if (filestr) {
+ /* FIXME: prevent string overflow */
file2pos = strlen(filestr);
memcpy(filestr2, filestr, file2pos);
- filestr2[file2pos] = '/';
+ if (( filestr2[file2pos - 1] == SEP )) {
+ file2pos--;
+ } else {
+ filestr2[file2pos] = SEP;
+ }
}
- strcpy(filestr2 + file2pos + 1, de->d_name);*/
+ strcpy(filestr2 + file2pos + 1, de->d_name);
errno = 0;
- status = stat(de->d_name, &fdstat);
+ ROSH_DEBUG2("stat(%s) ", filestr2);
+ status = stat(filestr2, &fdstat);
ROSH_DEBUG2("\t--stat()=%d\terr=%d\n", status, errno);
if (errno) {
rosh_error(errno, "ls:szmd.stat", de->d_name);
@@ -754,16 +760,17 @@ void rosh_st_mode2str(mode_t st_mode, char *st_mode_str)
* de directory entry
* optarr Array of options
*/
-void rosh_ls_arg_dir_de(struct dirent *de, const int *optarr)
+void rosh_ls_arg_dir_de(const char *filestr, struct dirent *de, const int *optarr)
{
int de_size;
mode_t st_mode;
char st_mode_str[11];
st_mode = 0;
+ ROSH_DEBUG2("+");
if (optarr[2] > -1)
- printf("%10d ", (int)de->d_ino);
+ printf("%10d ", (int)(de->d_ino));
if (optarr[0] > -1) {
- de_size = rosh_ls_de_size_mode(de, &st_mode);
+ de_size = rosh_ls_de_size_mode(filestr, de, &st_mode);
rosh_st_mode2str(st_mode, st_mode_str);
ROSH_DEBUG2("%04X ", st_mode);
printf("%s %10d ", st_mode_str, de_size);
@@ -791,7 +798,7 @@ void rosh_ls_arg_dir(const char *filestr, DIR * d, const int *optarr)
errno = 0;
while ((de = readdir(d))) {
filepos++;
- rosh_ls_arg_dir_de(de, optarr);
+ rosh_ls_arg_dir_de(filestr, de, optarr);
}
if (errno) {
rosh_error(errno, "ls:arg_dir", filestr);
@@ -846,7 +853,7 @@ void rosh_ls_arg(const char *filestr, const int *optarr)
} else {
ROSH_DEBUG("PATH '%s' is some other file\n", filestr);
}
- rosh_ls_arg_dir_de(&de, optarr);
+ rosh_ls_arg_dir_de(NULL, &de, optarr);
/* if (ifilstr[0] == SEP)
rosh_ls_arg_dir_de(NULL, &de, optarr);
else
diff --git a/com32/rosh/rosh.h b/com32/rosh/rosh.h
index cabf556a..87c15b7d 100644
--- a/com32/rosh/rosh.h
+++ b/com32/rosh/rosh.h
@@ -63,6 +63,8 @@
# define ROSH_DEBUG2(f, ...) ((void)0)
# define ROSH_DEBUG2_ARGV_V(argc, argv) ((void)0)
#endif /* DO_DEBUG */
+#define ROSH_DEBUG2_STAT(f, ...) ((void)0)
+// #define ROSH_DEBUG2_STAT ROSH_DEBUG2
#ifdef __COM32__
#define ROSH_IS_COM32 1
@@ -79,16 +81,21 @@ int stat(const char *pathname, struct stat *buf)
int fd, status, ret = -1;
DIR *d;
+ ROSH_DEBUG2_STAT("stat:opendir(%s) ", pathname);
d = opendir(pathname);
if (d != NULL) {
+ ROSH_DEBUG2_STAT("stat:closedir() ");
closedir(d);
ret = 0;
buf->st_mode = S_IFDIR | 0555;
buf->st_size = 0;
} else if ((errno == 0) || (errno == ENOENT) || (errno == ENOTDIR)) {
+ ROSH_DEBUG2_STAT("(%d)stat:open() ", errno);
fd = open(pathname, O_RDONLY);
- if (fd != 1) {
+ if (fd != -1) {
+ ROSH_DEBUG2_STAT("(%d)stat:fstat() ", fd);
status = fstat(fd, buf);
+ ROSH_DEBUG2_STAT("stat:close() ");
close(fd);
ret = 0;
}