/* * SPDsoft * ex: set tabstop=4 */ #include #ifndef WIN32 # include # include #if defined(DIRENT) # include typedef struct dirent dir_type; #else # include typedef struct direct dir_type; #endif # include /* chdir */ #else # include # include # include # include # ifdef MAXPATHLEN # undefine MAXPATHLEN # endif # define MAXPATHLEN _MAX_PATH # define getcwd _getcwd # define chdir _chdir #endif int rd(char *argv); int main(int argc, char **argv) { char cwd[64]; #ifndef WIN32 char pwd[MAXPATHLEN]; #endif char *s; if (getcwd(cwd, sizeof(cwd)) == NULL) { perror("pwd"); exit(2); } printf("%s\n", cwd); rd( argv[1] ); if ( -1 == chdir( argv[2] )) { perror("chdir"); return(1); } if ((s = getcwd(NULL, 64)) == NULL) { perror("pwd"); exit(2); } printf("getcwd: %s\n", s); free(s); #ifndef WIN32 printf("getwd: %s\n", getwd(pwd)); #endif return rd( "." ); } int rd(char *argv) { #ifndef WIN32 DIR *dir; dir_type *sd; if ( NULL == (dir = opendir( argv ))) { perror("opendir"); return(1); } else { while ( NULL != ( sd = readdir( dir ))) { fprintf(stdout, "%p %10d %24s\n", sd, sd->d_ino, sd->d_name); } closedir( dir ); return(0); } #else struct _finddata_t c_file; long hFile; /* Find first file in current directory */ if( (hFile = _findfirst( "*", &c_file )) == -1L ) { perror("opendir"); return(1); } else { printf( "Listing of files\n\n" ); printf( "\n RDO HID SYS ARC FILE DATE %25c SIZE\n", ' ' ); printf( " --- --- --- --- ---- ---- %25c ----\n", ' ' ); do { printf( ( c_file.attrib & _A_SUBDIR ) ? "d " : "- " ); printf( ( c_file.attrib & _A_RDONLY ) ? " Y " : " N " ); printf( ( c_file.attrib & _A_SYSTEM ) ? " Y " : " N " ); printf( ( c_file.attrib & _A_HIDDEN ) ? " Y " : " N " ); printf( ( c_file.attrib & _A_ARCH ) ? " Y " : " N " ); printf( " %-12s %.24s %9ld\n", c_file.name, ctime( &( c_file.time_write ) ), c_file.size ); } while( _findnext( hFile, &c_file ) == 0 ); _findclose( hFile ); return(0); } #endif } /* * WIN32 attrib meanings * _A_ARCH: Archive. Set whenever the file is changed, and cleared by the BACKUP command. Value: 0x20 _A_HIDDEN: Hidden file. Not normally seen with the DIR command, unless the /AH option is used. Returns information about normal files as well as files with this attribute. Value: 0x02 _A_NORMAL: Normal. File can be read or written to without restriction. Value: 0x00 _A_RDONLY: Read-only. File cannot be opened for writing, and a file with the same name cannot be created. Value: 0x01 _A_SUBDIR: Subdirectory. Value: 0x10 _A_SYSTEM: System file. Not normally seen with the DIR command, unless the /A or /A:S option is used. Value: 0x0 */