Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/types.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <limits.h>
- #ifdef FLOCK
- // define this, and it will hang on pipes, like this
- // rmio -v $(<stillneed)
- // rmio -v $(cat stillneed)
- // vs
- // rmio -v <stillneed
- // but not, true pipes, like,
- // cp rmio* /tmp/ ; cd /tmp
- // ls -1 r*| rmio -v
- // was that what I wanted?
- // otherwise, sees pointless,
- // as flockfile(FILE *) ;
- // seems to be for coprocesses, and threads, or coroutines, etc.
- // true for uname -sr = NetBSD 5.2.3
- #endif
- void usage(void);
- int verbose;
- int directory;
- int main ( int argc, char * argv[] )
- {
- int numerrs=0;
- char pathbuf[PATH_MAX*2];
- int len; /* current path length */
- char delim; /* delimiter */
- int c;
- delim='\n'; /* newline */
- verbose=0;
- directory=0;
- do { /* option processing w/ getopt */
- c=getopt(argc,argv, "z0nvdh?");
- switch(c) {
- case 'z':
- case '0':
- delim='\0'; /* Null char , find . -print0 */
- break;
- case 'n':
- delim='\n'; /* newline */
- break;
- case 'v':
- verbose=1 ;
- break;
- case 'd':
- directory=1;
- puts("Feature not implemented.");
- /*drop */
- case '?':
- case 'h':
- usage();
- return 1;
- }
- } while (c != -1 ) ;
- argc -= optind;
- argv += optind;
- len=0;
- #ifdef FLOCK
- flockfile(stdin);
- #endif
- for (;;) {
- c=getc(stdin);
- if ( EOF == c )
- break; /* break out of loop */
- if ( c != delim )
- pathbuf[len++]=c; /* fill in pathbuf */
- else {
- pathbuf[len]=0; /* make buf into string */
- if (verbose )
- puts(pathbuf);
- if ( unlink(pathbuf) ) { /* unlink the file or directory*/
- perror("unlink:");
- fputs(pathbuf,stderr);
- fputs("\n", stderr);
- numerrs++;
- }
- len=0;
- }
- }
- #ifdef FLOCK
- funlockfile(stdin);
- #endif
- return numerrs;
- }
- void usage(void)
- {
- puts("rmio -z0nvhd?");
- puts("");
- puts(" z/0 null delimited -- find . -print 0 ");
- puts(" n \\n delimited");
- puts(" v print file name, before attempting unlink");
- puts(" d stack non empty directories, in order to try again");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement