]>
Commit | Line | Data |
---|---|---|
e246ba5f | 1 | /* |
da23017d NS |
2 | * Copyright (c) 2003-2005 Silicon Graphics, Inc. |
3 | * All Rights Reserved. | |
dfc130f3 | 4 | * |
da23017d NS |
5 | * This program is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU General Public License as | |
e246ba5f | 7 | * published by the Free Software Foundation. |
dfc130f3 | 8 | * |
da23017d NS |
9 | * This program is distributed in the hope that it would be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | * GNU General Public License for more details. | |
dfc130f3 | 13 | * |
da23017d NS |
14 | * You should have received a copy of the GNU General Public License |
15 | * along with this program; if not, write the Free Software Foundation, | |
16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
e246ba5f NS |
17 | */ |
18 | ||
6b803e5a CH |
19 | #include "command.h" |
20 | #include "input.h" | |
e246ba5f | 21 | #include "init.h" |
48c46ee3 | 22 | #include "io.h" |
e246ba5f NS |
23 | |
24 | static cmdinfo_t truncate_cmd; | |
25 | ||
26 | static int | |
27 | truncate_f( | |
48c46ee3 NS |
28 | int argc, |
29 | char **argv) | |
e246ba5f | 30 | { |
48c46ee3 | 31 | off64_t offset; |
2c2f6d79 | 32 | size_t blocksize, sectsize; |
e246ba5f | 33 | |
48c46ee3 | 34 | init_cvtnum(&blocksize, §size); |
f72d20ad | 35 | offset = cvtnum(blocksize, sectsize, argv[1]); |
638473d8 | 36 | if (offset < 0) { |
e246ba5f NS |
37 | printf(_("non-numeric truncate argument -- %s\n"), argv[1]); |
38 | return 0; | |
39 | } | |
40 | ||
48c46ee3 | 41 | if (ftruncate64(file->fd, offset) < 0) { |
e246ba5f NS |
42 | perror("ftruncate"); |
43 | return 0; | |
44 | } | |
45 | return 0; | |
46 | } | |
47 | ||
48 | void | |
49 | truncate_init(void) | |
50 | { | |
ad765595 AM |
51 | truncate_cmd.name = "truncate"; |
52 | truncate_cmd.altname = "t"; | |
e246ba5f NS |
53 | truncate_cmd.cfunc = truncate_f; |
54 | truncate_cmd.argmin = 1; | |
55 | truncate_cmd.argmax = 1; | |
48c46ee3 | 56 | truncate_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK; |
e246ba5f NS |
57 | truncate_cmd.args = _("off"); |
58 | truncate_cmd.oneline = | |
59 | _("truncates the current file at the given offset"); | |
60 | ||
61 | add_command(&truncate_cmd); | |
62 | } |