Changes in uspace/srv/devman/util.c [dc87f3fd:4022513] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/util.c
rdc87f3fd r4022513 91 91 } 92 92 93 char *clone_string(const char *s)94 {95 size_t size = str_size(s) + 1;96 char *str;97 98 str = (char *) malloc(size);99 if (str != NULL)100 str_cpy(str, size, s);101 return str;102 }103 104 93 void replace_char(char *str, char orig, char repl) 105 94 { … … 111 100 } 112 101 113 ssize_t safe_read(int fd, void *buffer, size_t size)114 {115 if (size == 0) {116 return 0;117 }118 119 uint8_t *buf_ptr = (uint8_t *) buffer;120 121 size_t total_read = 0;122 while (total_read < size) {123 ssize_t bytes_read = read(fd, buf_ptr, size - total_read);124 if (bytes_read < 0) {125 /* Error. */126 return bytes_read;127 } else if (bytes_read == 0) {128 /* Possibly end of file. */129 break;130 } else {131 /* Read at least something. */132 buf_ptr += bytes_read;133 total_read += bytes_read;134 }135 }136 137 return (ssize_t) total_read;138 }139 140 102 /** @} 141 103 */
Note:
See TracChangeset
for help on using the changeset viewer.