37 #include <sys/types.h>
38 #include <sys/param.h>
42 # define MAXPATHLEN BUFSIZ
45 static char temp[] =
"intoXXXXXX";
46 static char buf[MAXPATHLEN+1];
63 if (argc >= 2 && !strcmp(argv[1],
"-f"))
70 fprintf(stderr,
"Usage: into [ -f ] file\n");
73 if (!
forceflg && access(argv[1], 2) < 0 && errno != ENOENT)
75 fprintf(stderr,
"into: ");
80 if ( (cp =
rindex( argv[1],
'/' )) != NULL )
84 strcpy(
buf, argv[1] );
93 if ( (outf = fopen(
buf,
"w" )) == NULL )
99 while ( (size = fread(iobuf, 1,
sizeof iobuf, stdin)) != 0)
100 fwrite(iobuf, 1, size, outf);
102 if ( !
forceflg && ftell(outf) == 0L )
104 fprintf( stderr,
"into: empty output, \"%s\" not modified\n", argv[1]);
111 fprintf(stderr,
"into: %s, \"%s\" not modified\n",
112 strerror(errno), argv[1]);
118 if ( rename(
buf, argv[1] ) < 0 )
120 fprintf(stderr,
"into: rename(%s, %s): ",
buf, argv[1]);
127 rename( file1, file2 )
132 if ( stat(file2, &st) >= 0 && unlink(file2) < 0 )
134 if ( link(file1, file2) < 0 )
136 return unlink( file1 );
void main(int argc, char **argv)