This repository was archived by the owner on Apr 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathio.h
More file actions
89 lines (79 loc) · 2.51 KB
/
io.h
File metadata and controls
89 lines (79 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Copyright 2017 Confluent Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#ifndef KIBOSH_IO_H
#define KIBOSH_IO_H
#include <unistd.h> // for ssize_t, size_t
/**
* Write a series of bytes to a file.
*
* @param fd The file descriptor.
* @param b The buffer.
* @param c The number of bytes to write.
*
* @return A negative error number on error, or 0 on success.
*/
ssize_t safe_write(int fd, const void *b, size_t c);
/**
* Write a null-terminated string to a file.
*
* @param path The path.
* @param str The null-terminated string..
*
* @return A negative error number on error, or 0 on success.
*/
int write_string_to_file(const char *path, const char *str);
/**
* Read a series of bytes from a file.
*
* @param fd The file descriptor.
* @param buf The buffer.
* @param buf_len The maximum number of bytes to read.
*
* @return A negative error number on error, or the number of bytes
* read on success.
*/
ssize_t safe_read(int fd, void *b, size_t c);
/**
* Read a null-terminated string from the given file descriptor.
*
* @param fd The file descriptor.
* @param buf The buffer.
* @param buf_len The length of the buffer.
*
* @return a negative error number on error, or 0 on success.
*/
int read_string_from_fd(int fd, char *buf, size_t buf_len);
/**
* Read a null-terminated string from the given file path.
*
* @param path The path.
* @param buf The buffer.
* @param buf_len The length of the buffer.
*
* @return a negative error number on error, or 0 on success.
*/
int read_string_from_file(const char *path, char *buf, size_t buf_len);
/**
* Copy the content of one file descriptor in another, using an intermediate buffer.
*
* @param dest_fd The destination fd.
* @param src_fd The source fd.
*
* @return 0 on success; a negative error code otherwise.
*/
int duplicate_fd(int dest_fd, int src_fd);
#endif
// vim: ts=4:sw=4:tw=99:et