Mercurial > hg > toybox
comparison toys/other/truncate.c @ 694:786841fdb1e0
Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
The actual code should be the same afterward, this is just cosmetic refactoring.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 13 Nov 2012 17:14:08 -0600 |
parents | 7e846e281e38 |
children | 6cc69be43c42 |
comparison
equal
deleted
inserted
replaced
693:4a5a250e0633 | 694:786841fdb1e0 |
---|---|
1 /* vi: set sw=4 ts=4: | 1 /* truncate.c - set file length, extending sparsely if necessary |
2 * | |
3 * truncate.c - set file length, extending sparsely if necessary | |
4 * | 2 * |
5 * Copyright 2011 Rob Landley <rob@landley.net> | 3 * Copyright 2011 Rob Landley <rob@landley.net> |
6 | 4 |
7 USE_TRUNCATE(NEWTOY(truncate, "<1s#|c", TOYFLAG_BIN)) | 5 USE_TRUNCATE(NEWTOY(truncate, "<1s#|c", TOYFLAG_BIN)) |
8 | 6 |
9 config TRUNCATE | 7 config TRUNCATE |
10 bool "truncate" | 8 bool "truncate" |
11 default y | 9 default y |
12 help | 10 help |
13 usage: truncate [-c] -s file... | 11 usage: truncate [-c] -s file... |
14 Set length of file(s), extending sparsely if necessary. | |
15 | 12 |
16 -c Don't create file if it doesn't exist. | 13 Set length of file(s), extending sparsely if necessary. |
17 -s New size | 14 |
15 -c Don't create file if it doesn't exist. | |
16 -s New size | |
18 */ | 17 */ |
19 | 18 |
20 #define FOR_truncate | 19 #define FOR_truncate |
21 #include "toys.h" | 20 #include "toys.h" |
22 | 21 |
23 GLOBALS( | 22 GLOBALS( |
24 long size; | 23 long size; |
25 ) | 24 ) |
26 | 25 |
27 static void do_truncate(int fd, char *name) | 26 static void do_truncate(int fd, char *name) |
28 { | 27 { |
29 if (fd<0) return; | 28 if (fd<0) return; |
30 if (ftruncate(fd, TT.size)) { | 29 if (ftruncate(fd, TT.size)) { |
31 perror_msg("failed to set '%s' to '%ld'", name, TT.size); | 30 perror_msg("failed to set '%s' to '%ld'", name, TT.size); |
32 toys.exitval = EXIT_FAILURE; | 31 toys.exitval = EXIT_FAILURE; |
33 } | 32 } |
34 } | 33 } |
35 | 34 |
36 void truncate_main(void) | 35 void truncate_main(void) |
37 { | 36 { |
38 int cr = !(toys.optflags&1); | 37 int cr = !(toys.optflags&1); |
39 | 38 |
40 // Create files with mask rwrwrw. | 39 // Create files with mask rwrwrw. |
41 // Nonexistent files are only an error if we're supposed to create them. | 40 // Nonexistent files are only an error if we're supposed to create them. |
42 loopfiles_rw(toys.optargs, O_WRONLY|(cr ? O_CREAT : 0), 0666, cr, | 41 loopfiles_rw(toys.optargs, O_WRONLY|(cr ? O_CREAT : 0), 0666, cr, |
43 do_truncate); | 42 do_truncate); |
44 } | 43 } |