1 /* Copyright (c) 2006-2013 Jonas Fonseca <fonseca@diku.dk>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
20 * Argument array helpers.
23 bool argv_to_string(const char *argv
[SIZEOF_ARG
], char *buf
, size_t buflen
, const char *sep
);
24 bool argv_from_string_no_quotes(const char *argv
[SIZEOF_ARG
], int *argc
, char *cmd
);
25 bool argv_from_string(const char *argv
[SIZEOF_ARG
], int *argc
, char *cmd
);
26 bool argv_from_env(const char **argv
, const char *name
);
27 void argv_free(const char *argv
[]);
28 size_t argv_size(const char **argv
);
29 bool argv_append(const char ***argv
, const char *arg
);
30 bool argv_append_array(const char ***dst_argv
, const char *src_argv
[]);
31 bool argv_copy(const char ***dst
, const char *src
[]);
32 bool argv_remove_quotes(const char *argv
[]);
33 bool argv_contains(const char **argv
, const char *arg
);
36 * Encoding conversion.
39 #define ENCODING_UTF8 "UTF-8"
43 struct encoding
*encoding_open(const char *fromcode
);
44 char *encoding_convert(struct encoding
*encoding
, char *line
);
45 const char *encoding_iconv(iconv_t iconv_out
, const char *string
);
46 struct encoding
*get_path_encoding(const char *path
, struct encoding
*default_encoding
);
48 extern char encoding_arg
[];
49 extern struct encoding
*default_encoding
;
52 * Executing external commands.
56 IO_FD
, /* File descriptor based IO. */
57 IO_BG
, /* Execute command in the background. */
58 IO_FG
, /* Execute command with same std{in,out,err}. */
59 IO_RD
, /* Read only fork+exec IO. */
60 IO_RD_STDIN
, /* Read only fork+exec IO with stdin. */
61 IO_WR
, /* Write only fork+exec IO. */
62 IO_AP
, /* Append fork+exec output to file. */
66 int pipe
; /* Pipe end for reading or writing. */
67 pid_t pid
; /* PID of spawned process. */
68 int error
; /* Error status. */
69 char *buf
; /* Read buffer. */
70 size_t bufalloc
; /* Allocated buffer size. */
71 size_t bufsize
; /* Buffer content size. */
72 char *bufpos
; /* Current buffer position. */
73 unsigned int eof
:1; /* Has end of file been reached. */
74 int status
:8; /* Status exit code. */
77 typedef int (*io_read_fn
)(char *, size_t, char *, size_t, void *data
);
79 bool io_open(struct io
*io
, const char *fmt
, ...) PRINTF_LIKE(2, 3);
80 bool io_kill(struct io
*io
);
81 bool io_done(struct io
*io
);
82 bool io_run(struct io
*io
, enum io_type type
, const char *dir
, char * const env
[], const char *argv
[], ...);
83 bool io_run_bg(const char **argv
);
84 bool io_run_fg(const char **argv
, const char *dir
);
85 bool io_run_append(const char **argv
, int fd
);
86 bool io_eof(struct io
*io
);
87 int io_error(struct io
*io
);
88 char * io_strerror(struct io
*io
);
89 bool io_can_read(struct io
*io
, bool can_block
);
90 ssize_t
io_read(struct io
*io
, void *buf
, size_t bufsize
);
91 char * io_get(struct io
*io
, int c
, bool can_read
);
92 bool io_write(struct io
*io
, const void *buf
, size_t bufsize
);
93 bool io_printf(struct io
*io
, const char *fmt
, ...) PRINTF_LIKE(2, 3);
94 bool io_read_buf(struct io
*io
, char buf
[], size_t bufsize
);
95 bool io_run_buf(const char **argv
, char buf
[], size_t bufsize
);
96 int io_load(struct io
*io
, const char *separators
,
97 io_read_fn read_property
, void *data
);
98 int io_run_load(const char **argv
, const char *separators
,
99 io_read_fn read_property
, void *data
);
101 const char *get_temp_dir(void);
104 /* vim: set ts=8 sw=8 noexpandtab: */