Changeset 80bfb601 in mainline for uspace/lib/c/generic/sysinfo.c
- Timestamp:
- 2010-04-18T09:57:19Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d869398
- Parents:
- fce3536
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/sysinfo.c
rfce3536 r80bfb601 40 40 #include <bool.h> 41 41 42 /** Get sysinfo item type 43 * 44 * @param path Sysinfo path. 45 * 46 * @return Sysinfo item type. 47 * 48 */ 42 49 sysinfo_item_tag_t sysinfo_get_tag(const char *path) 43 50 { … … 46 53 } 47 54 55 /** Get sysinfo numerical value 56 * 57 * @param path Sysinfo path. 58 * @param value Pointer to store the numerical value to. 59 * 60 * @return EOK if the value was successfully read and 61 * is of SYSINFO_VAL_VAL type. 62 * 63 */ 48 64 int sysinfo_get_value(const char *path, sysarg_t *value) 49 65 { … … 52 68 } 53 69 70 /** Get sysinfo binary data size 71 * 72 * @param path Sysinfo path. 73 * @param value Pointer to store the binary data size. 74 * 75 * @return EOK if the value was successfully read and 76 * is of SYSINFO_VAL_DATA type. 77 * 78 */ 54 79 static int sysinfo_get_data_size(const char *path, size_t *size) 55 80 { … … 58 83 } 59 84 85 /** Get sysinfo binary data 86 * 87 * @param path Sysinfo path. 88 * @param value Pointer to store the binary data size. 89 * 90 * @return Binary data read from sysinfo or NULL if the 91 * sysinfo item value type is not binary data. 92 * The returned non-NULL pointer should be 93 * freed by free(). 94 * 95 */ 60 96 void *sysinfo_get_data(const char *path, size_t *size) 61 97 { 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. 101 102 Let's hope that the number of iterations is bounded 103 in common cases. */ 104 62 105 while (true) { 106 /* Get the binary data size */ 63 107 int ret = sysinfo_get_data_size(path, size); 64 if (ret != EOK) 108 if (ret != EOK) { 109 /* Not binary data item */ 65 110 return NULL; 111 } 66 112 67 113 void *data = malloc(*size); … … 69 115 return NULL; 70 116 117 /* Get the data */ 71 118 ret = __SYSCALL4(SYS_SYSINFO_GET_DATA, (sysarg_t) path, 72 119 (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size); … … 74 121 return data; 75 122 123 /* Dispose the buffer */ 76 124 free(data); 77 125 78 if (ret != ENOMEM) 126 if (ret != ENOMEM) { 127 /* The failure to get the data was not caused 128 by wrong buffer size */ 79 129 return NULL; 130 } 80 131 } 81 132 }
Note:
See TracChangeset
for help on using the changeset viewer.