Changes in uspace/lib/c/generic/sysinfo.c [311bc25:bbda5ab] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/sysinfo.c
r311bc25 rbbda5ab 96 96 void *sysinfo_get_data(const char *path, size_t *size) 97 97 { 98 /* 99 * The binary data size might change during time. 100 * Unfortunatelly we cannot allocate the buffer 101 * and transfer the data as a single atomic operation. 102 */ 98 /* The binary data size might change during time. 99 Unfortunatelly we cannot allocate the buffer 100 and transfer the data as a single atomic operation. 103 101 104 /* Get the binary data size */ 105 int ret = sysinfo_get_data_size(path, size); 106 if ((ret != EOK) || (size == 0)) { 107 /* 108 * Not a binary data item 109 * or an empty item. 110 */ 111 *size = 0; 112 return NULL; 102 Let's hope that the number of iterations is bounded 103 in common cases. */ 104 105 void *data = NULL; 106 107 while (true) { 108 /* Get the binary data size */ 109 int ret = sysinfo_get_data_size(path, size); 110 if ((ret != EOK) || (size == 0)) { 111 /* Not a binary data item 112 or an empty item */ 113 break; 114 } 115 116 data = realloc(data, *size); 117 if (data == NULL) 118 break; 119 120 /* Get the data */ 121 ret = __SYSCALL4(SYS_SYSINFO_GET_DATA, (sysarg_t) path, 122 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size); 123 if (ret == EOK) 124 return data; 125 126 if (ret != ENOMEM) { 127 /* The failure to get the data was not caused 128 by wrong buffer size */ 129 break; 130 } 113 131 } 114 132 115 void *data = malloc(*size); 116 if (data == NULL) { 117 *size = 0; 118 return NULL; 119 } 133 if (data != NULL) 134 free(data); 120 135 121 /* Get the data */122 size_t sz;123 ret = __SYSCALL5(SYS_SYSINFO_GET_DATA, (sysarg_t) path,124 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size,125 (sysarg_t) &sz);126 if (ret == EOK) {127 *size = sz;128 return data;129 }130 131 free(data);132 136 *size = 0; 133 137 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.