Version 1.8.0.0
[socat.git] / xiolayer.c
blob83b883966a7e9e163b0edb355f4303341fb2f143
1 /* source: xiolayer.c */
2 /* Copyright Gerhard Rieger and contributors (see file CHANGES) */
3 /* Published under the GNU General Public License V.2, see file COPYING */
5 /* this file contains the source for common options */
7 #include "xiosysincludes.h"
8 #include "xioopen.h"
10 #include "xiolayer.h"
12 /****** for ALL addresses - by application ******/
13 const struct optdesc opt_ignoreeof = { "ignoreeof", NULL, OPT_IGNOREEOF, GROUP_APPL, PH_LATE, TYPE_BOOL, OFUNC_EXT, XIO_OFFSETOF(ignoreeof), XIO_SIZEOF(ignoreeof) };
14 const struct optdesc opt_cr = { "cr", NULL, OPT_CR, GROUP_APPL, PH_LATE, TYPE_CONST, OFUNC_EXT, XIO_OFFSETOF(lineterm), XIO_SIZEOF(lineterm), LINETERM_CR };
15 const struct optdesc opt_crnl = { "crnl", NULL, OPT_CRNL, GROUP_APPL, PH_LATE, TYPE_CONST, OFUNC_EXT, XIO_OFFSETOF(lineterm), XIO_SIZEOF(lineterm), LINETERM_CRNL };
16 const struct optdesc opt_readbytes = { "readbytes", "bytes", OPT_READBYTES, GROUP_APPL, PH_LATE, TYPE_SIZE_T, OFUNC_EXT, XIO_OFFSETOF(readbytes), XIO_SIZEOF(readbytes) };
17 const struct optdesc opt_lockfile = { "lockfile", NULL, OPT_LOCKFILE, GROUP_APPL, PH_INIT, TYPE_FILENAME, OFUNC_EXT, 0, 0 };
18 const struct optdesc opt_waitlock = { "waitlock", NULL, OPT_WAITLOCK, GROUP_APPL, PH_INIT, TYPE_FILENAME, OFUNC_EXT, 0, 0 };
19 const struct optdesc opt_escape = { "escape", NULL, OPT_ESCAPE, GROUP_APPL, PH_INIT, TYPE_INT, OFUNC_OFFSET, XIO_OFFSETOF(escape), sizeof(((xiosingle_t *)0)->escape) };
20 /****** APPL addresses ******/
21 #if WITH_RETRY
22 const struct optdesc opt_forever = { "forever", NULL, OPT_FOREVER, GROUP_RETRY, PH_INIT, TYPE_BOOL, OFUNC_EXT, XIO_OFFSETOF(forever), XIO_SIZEOF(forever) };
23 const struct optdesc opt_intervall = { "interval", NULL, OPT_INTERVALL, GROUP_RETRY, PH_INIT, TYPE_TIMESPEC, OFUNC_EXT, XIO_OFFSETOF(intervall), XIO_SIZEOF(intervall) };
24 const struct optdesc opt_retry = { "retry", NULL, OPT_RETRY, GROUP_RETRY, PH_INIT, TYPE_UINT, OFUNC_EXT, XIO_OFFSETOF(retry), XIO_SIZEOF(retry) };
25 #endif
27 const struct optdesc opt_chdir = { "chdir", "cd", OPT_CHDIR, GROUP_ADDR, PH_INIT, TYPE_FILENAME, OFUNC_SPEC };
28 const struct optdesc opt_umask = { "umask", NULL, OPT_UMASK, GROUP_ADDR, PH_INIT, TYPE_MODET, OFUNC_SPEC };
31 int xio_chdir(
32 struct opt* opts,
33 char **orig_dir)
35 char *tmp_dir = NULL;
37 if (retropt_string(opts, OPT_CHDIR, &tmp_dir) < 0)
38 return 0;
40 if ((*orig_dir = Malloc(PATH_MAX)) == NULL) {
41 free(tmp_dir);
42 return -1;
45 if (getcwd(*orig_dir, PATH_MAX) == NULL) {
46 Error1("getcwd(<ptr>, PATH_MAX): %s", strerror(errno));
47 free(*orig_dir);
48 free(tmp_dir);
49 return -1;
51 *orig_dir = Realloc(*orig_dir, strlen(*orig_dir)+1);
53 if (Chdir(tmp_dir) < 0) {
54 Error2("chdir(\"%s\"): %s", tmp_dir, strerror(errno));
55 free(*orig_dir);
56 free(tmp_dir);
57 return -1;
60 free(tmp_dir);
61 return 1;