Skip to content

Commit

Permalink
Merge remote branch 'genec/rosh_for_hpa'
Browse files Browse the repository at this point in the history
  • Loading branch information
H. Peter Anvin committed Mar 2, 2011
2 parents 6af6965 + 28f3eaa commit 051e3b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
43 changes: 25 additions & 18 deletions 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
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion com32/rosh/rosh.h
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down

0 comments on commit 051e3b6

Please sign in to comment.