External ulility mycat.
More...
|
| enum | error_code {
UNKNOWN_OPT = 1
, NO_FILES = 2
, ALLOC_ERR = 3
, OPEN_ERR = 4
,
STAT_ERR = 5
, READ_ERR = 6
, WRITE_ERR = 7
} |
| |
|
| void | herror (error_code code, int use_errno,...) |
| |
| void | help (void) |
| |
| int | wrbuf (int fd, const char *buffer, ssize_t size) |
| |
| int | rdbuf (int fd, char *buffer, ssize_t size) |
| |
| void | chtoh (char c, char *hex_escape) |
| |
| ssize_t | buftoh (const char *buffer, ssize_t size, char *fbuffer) |
| |
| void | rfiles (int argc, char *argv[], struct file *files) |
| |
| void | cat (const struct file *file, int a_flag, char *buffer, char *fbuffer) |
| |
|
int | main (int argc, char *argv[]) |
| |
◆ error_code
◆ buftoh()
| ssize_t buftoh |
( |
const char * | buffer, |
|
|
ssize_t | size, |
|
|
char * | fbuffer ) |
Escapes non-printable characters in buffer and writes the result to fbuffer
- Parameters
-
| buffer | Buffer to filter |
| size | Size of the buffer |
| fbuffer | Buffer to write the result to |
- Returns
- Number of bytes written to
fbuffer
◆ cat()
| void cat |
( |
const struct file * | file, |
|
|
int | a_flag, |
|
|
char * | buffer, |
|
|
char * | fbuffer ) |
Reads file file and writes it to stdout
- Parameters
-
| file | File to read |
| a_flag | If set to 1, non-printable characters will be replaced with their hexadecimal escape sequences |
| buffer | Buffer to read to |
| fbuffer | Auxiliary buffer for a_flag |
- Note
- Returns nothing. Exits on error.
- Warning
fbuffer may be NULL if a_flag is not set, otherwise behavior is undefined. fbuffer must be at least bytes long if a_flag is set.
◆ chtoh()
| void chtoh |
( |
char | c, |
|
|
char * | hex_escape ) |
Converts a character to its hexadecimal escape sequence
- Parameters
-
| c | Character to convert |
| hex_escape | Buffer to write the escape sequence to |
◆ help()
Prints help message to stdout
◆ herror()
| void herror |
( |
error_code | code, |
|
|
int | use_errno, |
|
|
| ... ) |
Prints error message to stderr and exits with the specified code
- See also
- error_code
- Parameters
-
| code | Error code |
| use_errno | If set to 1, the description of errno will be appended to the error message |
| ... | Additional arguments for the error message |
◆ rdbuf()
| int rdbuf |
( |
int | fd, |
|
|
char * | buffer, |
|
|
ssize_t | size ) |
Reads size bytes from fd to buffer
- Parameters
-
| fd | File descriptor |
| buffer | Buffer to read to |
| size | Size of the buffer |
- Returns
- 0 on success, -1 on error
- Note
- Automatically retries if
read() is interrupted
◆ rfiles()
| void rfiles |
( |
int | argc, |
|
|
char * | argv[], |
|
|
struct file * | files ) |
Opens files from argv and saves their metadata to files
- Parameters
-
| argc | Number of files |
| argv | Array of filenames |
| files | Array of struct file |
- Note
- Returns nothing. Exits on error.
◆ wrbuf()
| int wrbuf |
( |
int | fd, |
|
|
const char * | buffer, |
|
|
ssize_t | size ) |
Writes size bytes from buffer to fd
- Parameters
-
| fd | File descriptor |
| buffer | Buffer to write |
| size | Size of the buffer |
- Returns
- 0 on success, -1 on error
- Note
- Automatically retries if
write() is interrupted
◆ error_messages
| const char* error_messages[] |
|
static |
Initial value:= {
[UNKNOWN_OPT] = "Unknown option",
[NO_FILES] = "No input files provided",
[ALLOC_ERR] = "Memory allocation error",
[OPEN_ERR] = "Cannot open file %s",
[STAT_ERR] = "Cannot stat file %s",
[READ_ERR] = "Cannot read from file %s",
[WRITE_ERR] = "Cannot write to stdout"
}
Error messages