Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <dirent.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- void do_dir(const char * dirpath);
- int main ( int argc, char * argv[] )
- {
- do_dir(".");
- return 0;
- }
- char pathbuf[(4096*2)];
- /* I doubt that was it */
- /* no, it was, that needs be malloced.
- God, when did I start this weak stab at this?
- * right, a program that uses normal C string ops, stays runnable
- * longer, so actually, can perform, better, even though
- * counting strlen all the time, *is* wasteful, it's always
- * interruptable, the process is, when doing byte operations.
- * Programs spend resources in the Economy of Operations.
- * just use a 4GL, then anyone half try is basically just as GOOD.
- * hahah!
- *
- */
- void do_dir(const char * dirpath)
- {
- struct dirent entry,*entry_ptr;
- long loc;
- DIR * dir;
- char * pathbuf;
- {
- int len;
- len=4096+strlen(dirpath);
- pathbuf=malloc(len);
- if ( pathbuf == NULL ) {
- perror("malloc pathbuf");
- goto END;
- }
- }
- dir = opendir(dirpath);
- if ( NULL == dir )
- goto END;
- /* skip over . and .., but check for errors */
- if ( readdir_r(dir, &entry, &entry_ptr) ) {
- perror("reading dot");
- goto END;
- }
- if ( readdir_r(dir, &entry, &entry_ptr) ) {
- perror("reading dotdot");
- goto END;
- }
- loc=telldir(dir);
- do {
- readdir_r(dir, &entry, &entry_ptr);
- if ( entry_ptr == &entry )
- printf("%s/%s\n",dirpath,&entry.d_name);
- } while ( NULL != entry_ptr ) ;
- seekdir(dir,loc); /* jump back to after . and .. */
- /* now recurse into directories */
- /* ok, dan? but ur not recursing ? */
- do {
- readdir_r(dir, &entry, &entry_ptr);
- if ( entry_ptr == &entry && entry.d_type == DT_DIR ) {
- strcpy(pathbuf,dirpath);
- strcat(pathbuf,"/");
- strcat(pathbuf,entry.d_name);
- do_dir(pathbuf);
- }
- } while ( NULL != entry_ptr ) ;
- END:
- closedir(dir);
- free(pathbuf);
- }
- /* I call this dot and compile# gcc -o dot findot.c -O1 -g */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement