Reputation: 10834
I like to call truncate(const char *path, off_t length)
(see man 2 truncate
) directly from the command line or in shell script.
I guess I could embed a C program and then compile, run, and remove it.
Another short alternative is using perl -e "truncate($file,$length)"
.
Questions:
Is perl -e "syscall(params...)"
the most common pattern to invoke syscalls? How well does it cover other syscalls?
Is there another common way to invoke Linux/BSD syscalls from the shell?
For instance, using a command like syscall "truncate($file,$length)"
?
Upvotes: 2
Views: 441
Reputation: 10834
Thank you for all comments and suggestions. I conclude the following answers to my questions:
perl
, may provide functions that resemble or wrap some of the useful syscalls, i.e., those that would make sense calling from the shell.Moreover, a generic solution for a specific problem should not focus on syscalls in the first place, but rather use a generic language or library from the beginning. For instance, for file truncation this may actually be perl, using perl -e "truncate($file,$length)"
.
Upvotes: 4