Man page - s2argv(3)
Packages contains this manual
- eexecs(3)
- system_execsa(3)
- system_execsqp(3)
- system_execsqra(3)
- system_execsr(3)
- system_execsqrp(3)
- eexecspe(3)
- coprocspe(3)
- pclose_nosh(3)
- popen_execsp(3)
- system_execsra(3)
- coprocv(3)
- pclose_execs(3)
- coprocs(3)
- execs(3)
- execspe(3)
- system_nosh(3)
- system_eexecsp(3)
- coprocsp(3)
- pclose_execsp(3)
- esystem(3)
- coprocvp(3)
- coprocvpe(3)
- coprocse(3)
- system_execsqa(3)
- popen_execs(3)
- s2argv(3)
- popen_nosh(3)
- system_execsrp(3)
- eexecsp(3)
- execse(3)
- execsp(3)
- system_execs(3)
- coprocess(3)
- coprocve(3)
- system_execsp(3)
- system_safe(3)
- eexecse(3)
apt-get install libexecs-dev
Manual
S2ARGV
NAMESYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
SEE ALSO
BUGS
AUTHOR
NAME
s2argv - convert a command string in an argv array
SYNOPSIS
#include
<unistd.h>
#include <stdlib.h>
#include <execs.h>
char
**s2argv(const char *
args
);
void s2argv_free(char **
argv
);
size_t s2argvlen(char ** argv );
size_t s2argc(char ** argv );
typedef char
* (* s2argv_getvar_t) (const char *name);
extern s2argv_getvar_t s2argv_getvar;
These functions are provided by libexecs and libeexecs. Link with -lexecs or -leexecs .
DESCRIPTION
s2argv
convert a command string in an argv array for
execv
(3),
execvp
(3) or
execvpe
(3).
Single or double quotes can be used to delimitate command
arguments including spaces and a non quoted backslash
(
\
) is the escape character to protect the next char.
s2argv
can parse several commands separated by
semicolons (
;
). The argv of each command is
terminated by a NULL element, one further NULL element tags
the end of the array returned by s2argv.
s2argv
supports variables as arguments. When an argument
of a command is a dollar sign followed by a name (e.g.
$USER)
s2argv
puts the output of the
s2argv_getvar
function instead. (It is possible for
example to assign
s2argv_getvar=getenv
. For security
reasons, the function is NULL by default and all variables
get replaced with an empty string. Programmers can use their
own custom function instead).
s2argv_free frees the memory that was allocated by s2argv .
s2argvlen returns the sum of the s2argc for all the commands, including the trailing NULLs that separate them.
s2argc returns the number of arguemnts of the (first) command returned by s2argv . (The beginning of the next argv is argv+s2argc(argv)+1 ).
RETURN VALUE
s2argv returns a dynamically allocated argv, ready to be used as an argument to execv (3), execvp (3) or execvpe (3). The return value of s2argv should be freed by s2argv_free in case the exec command does not succeed.
EXAMPLE
The following program demonstrates the use of s2argv :
#include
<stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <execs.h>
#define BUFLEN
1024
int main(int argc, char *argv)
{
|
char buf[BUFLEN]; |
|||
|
printf("type in a command and its arguments, e.g. ’ls -l’\n"); |
|||
|
if (fgets(buf, BUFLEN, stdin) != NULL) { |
|||
|
char **argv=s2argv(buf); |
|||
|
execvp(argv[0], argv); |
|||
|
s2argv_free(argv); |
|||
|
printf("exec error\n"); |
|||
|
} |
}
SEE ALSO
exec (3)
BUGS
Bug reports should be addressed to <info@virtualsquare.org>
AUTHOR
Renzo Davoli <renzo@cs.unibo.it>