summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaLyong Cho <walyong.cho@samsung.com>2016-12-14 05:21:15 (GMT)
committerWaLyong Cho <walyong.cho@samsung.com>2016-12-14 05:45:47 (GMT)
commit37e3c166c7079ef304f16e2233e363ce3201ac0b (patch)
tree58911378f3ca7bb9a7a53f1cf6f3d0dd244d1360
parent0bf84e45ee6bb59bfab5dd37673f442db088062b (diff)
downloadlibsystem-37e3c166c7079ef304f16e2233e363ce3201ac0b.zip
libsystem-37e3c166c7079ef304f16e2233e363ce3201ac0b.tar.gz
libsystem-37e3c166c7079ef304f16e2233e363ce3201ac0b.tar.bz2
libsystem: add general numeric type read/write api.
Add new general numeric type(int, long int, long long int, unsigned int, unsigned long int, unsigned long long int) read/write api. Change-Id: I45fd85be237414619b12a96ea9e6351960c550d3 Signed-off-by: WaLyong Cho <walyong.cho@samsung.com>
-rw-r--r--src/libsystem/libsystem.c224
-rw-r--r--src/libsystem/libsystem.h276
2 files changed, 500 insertions, 0 deletions
diff --git a/src/libsystem/libsystem.c b/src/libsystem/libsystem.c
index a911745..c8b7c58 100644
--- a/src/libsystem/libsystem.c
+++ b/src/libsystem/libsystem.c
@@ -727,6 +727,230 @@ DEFINE_READ_WRITE_NUM_DUAL(uint32, "%u", "%u");
DEFINE_READ_WRITE_NUM_DUAL(int64, "%" SCNd64, "%" PRId64);
DEFINE_READ_WRITE_NUM_DUAL(uint64, "%" SCNu64, "%" PRIu64);
+int write_int_to_file(FILE *f, int num, enum file_write_flags flags) {
+
+ assert(f);
+ assert(num);
+
+ return write_int32_to_file(f, (int32_t) num, flags);
+}
+
+int write_int_to_path(const char *path, int num, enum file_write_flags flags) {
+
+ assert(path);
+ assert(num);
+
+ return write_int32_to_path(path, (int32_t) num, flags);
+}
+
+int write_unsigned_int_to_file(FILE *f, unsigned int num, enum file_write_flags flags) {
+
+ assert(f);
+ assert(num);
+
+ return write_uint32_to_file(f, (uint32_t) num, flags);
+}
+
+int write_unsigned_int_to_path(const char *path, unsigned int num, enum file_write_flags flags) {
+
+ assert(path);
+ assert(num);
+
+ return write_uint32_to_path(path, (uint32_t) num, flags);
+}
+
+int write_long_int_to_file(FILE *f, long int num, enum file_write_flags flags) {
+
+ assert(f);
+ assert(num);
+
+#if __WORDSIZE == 64
+ return write_int64_to_file(f, (int64_t) num, flags);
+#else
+ return write_int32_to_file(f, (int32_t) num, flags);
+#endif
+}
+
+int write_long_int_to_path(const char *path, long int num, enum file_write_flags flags) {
+
+ assert(path);
+ assert(num);
+
+#if __WORDSIZE == 64
+ return write_int64_to_path(path, (int64_t) num, flags);
+#else
+ return write_int32_to_path(path, (int32_t) num, flags);
+#endif
+}
+
+int write_unsigned_long_int_to_file(FILE *f, unsigned long int num, enum file_write_flags flags) {
+
+ assert(f);
+ assert(num);
+
+#if __WORDSIZE == 64
+ return write_uint64_to_file(f, (uint64_t) num, flags);
+#else
+ return write_uint32_to_file(f, (uint32_t) num, flags);
+#endif
+}
+
+int write_unsigned_long_int_to_path(const char *path, unsigned long int num, enum file_write_flags flags) {
+
+ assert(path);
+ assert(num);
+
+#if __WORDSIZE == 64
+ return write_uint64_to_path(path, (uint64_t) num, flags);
+#else
+ return write_uint32_to_path(path, (uint32_t) num, flags);
+#endif
+}
+
+int write_long_long_int_to_file(FILE *f, long long int num, enum file_write_flags flags) {
+
+ assert(f);
+ assert(num);
+
+ return write_int64_to_file(f, (int64_t) num, flags);
+}
+
+int write_long_long_int_to_path(const char *path, long long int num, enum file_write_flags flags) {
+
+ assert(path);
+ assert(num);
+
+ return write_int64_to_path(path, (int64_t) num, flags);
+}
+
+int write_unsigned_long_long_int_to_file(FILE *f, unsigned long long int num, enum file_write_flags flags) {
+
+ assert(f);
+ assert(num);
+
+ return write_uint64_to_file(f, (uint64_t) num, flags);
+}
+
+int write_unsigned_long_long_int_to_path(const char *path, unsigned long long int num, enum file_write_flags flags) {
+
+ assert(path);
+ assert(num);
+
+ return write_uint64_to_path(path, (uint64_t) num, flags);
+}
+
+int read_int_from_file(FILE *f, int *num) {
+
+ assert(f);
+ assert(num);
+
+ return read_int32_from_file(f, (int32_t *) num);
+}
+
+int read_int_from_path(const char *path, int *num) {
+
+ assert(path);
+ assert(num);
+
+ return read_int32_from_path(path, (int32_t *) num);
+}
+
+int read_unsigned_int_from_file(FILE *f, unsigned int *num) {
+
+ assert(f);
+ assert(num);
+
+ return read_uint32_from_file(f, (uint32_t *) num);
+}
+
+int read_unsigned_int_from_path(const char *path, unsigned int *num) {
+
+ assert(path);
+ assert(num);
+
+ return read_uint32_from_path(path, (uint32_t *) num);
+}
+
+int read_long_int_from_file(FILE *f, long int *num) {
+
+ assert(f);
+ assert(num);
+
+#if __WORDSIZE == 64
+ return read_int64_from_file(f, (int64_t *) num);
+#else
+ return read_int32_from_file(f, (int32_t *) num);
+#endif
+}
+
+int read_long_int_from_path(const char *path, long int *num) {
+
+ assert(path);
+ assert(num);
+
+#if __WORDSIZE == 64
+ return read_int64_from_path(path, (int64_t *) num);
+#else
+ return read_int32_from_path(path, (int32_t *) num);
+#endif
+}
+
+int read_unsigned_long_int_from_file(FILE *f, unsigned long int *num) {
+
+ assert(f);
+ assert(num);
+
+#if __WORDSIZE == 64
+ return read_uint64_from_file(f, (uint64_t *) num);
+#else
+ return read_uint32_from_file(f, (uint32_t *) num);
+#endif
+}
+
+int read_unsigned_long_int_from_path(const char *path, unsigned long int *num) {
+
+ assert(path);
+ assert(num);
+
+#if __WORDSIZE == 64
+ return read_uint64_from_path(path, (uint64_t *) num);
+#else
+ return read_uint32_from_path(path, (uint32_t *) num);
+#endif
+}
+
+int read_long_long_int_from_file(FILE *f, long long *num) {
+
+ assert(f);
+ assert(num);
+
+ return read_int64_from_file(f, (int64_t *) num);
+}
+
+int read_long_long_int_from_path(const char *path, long long *num) {
+
+ assert(path);
+ assert(num);
+
+ return read_int64_from_path(path, (int64_t *) num);
+}
+
+int read_unsigned_long_long_int_from_file(FILE *f, unsigned long long *num) {
+
+ assert(f);
+ assert(num);
+
+ return read_uint64_from_file(f, (uint64_t *) num);
+}
+
+int read_unsigned_long_long_int_from_path(const char *path, unsigned long long *num) {
+
+ assert(path);
+ assert(num);
+
+ return read_uint64_from_path(path, (uint64_t *) num);
+}
+
int str_to_strv(const char *str, char ***strv, const char *separator) {
char *w, *state, *p;
char **v = NULL, **new = NULL;
diff --git a/src/libsystem/libsystem.h b/src/libsystem/libsystem.h
index acd50dc..4452179 100644
--- a/src/libsystem/libsystem.h
+++ b/src/libsystem/libsystem.h
@@ -480,6 +480,162 @@ int write_uint64_to_file(FILE *f, uint64_t u, enum file_write_flags flags);
int write_uint64_to_path(const char *path, uint64_t u, enum file_write_flags flags);
/**
+ * @brief Write int to FILE.
+ *
+ * @param f File pointer
+ * @param num int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_int_to_file(FILE *f, int num, enum file_write_flags flags);
+
+/**
+ * @brief Write int to path.
+ *
+ * @param path File path.
+ * @param num int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_int_to_path(const char *path, int num, enum file_write_flags flags);
+
+/**
+ * @brief Write type unsigned int to FILE.
+ *
+ * @param f File pointer
+ * @param num unsigned int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_unsigned_int_to_file(FILE *f, unsigned int num, enum file_write_flags flags);
+
+/**
+ * @brief Write int to path.
+ *
+ * @param path File path.
+ * @param num int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_unsigned_int_to_path(const char *path, unsigned int num, enum file_write_flags flags);
+
+/**
+ * @brief Write long int to FILE.
+ *
+ * @param f File pointer
+ * @param num long int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_long_int_to_file(FILE *f, long int num, enum file_write_flags flags);
+
+/**
+ * @brief Write int to path.
+ *
+ * @param path File path.
+ * @param num int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_long_int_to_path(const char *path, long int num, enum file_write_flags flags);
+
+/**
+ * @brief Write unsigned long int to FILE.
+ *
+ * @param f File pointer
+ * @param num unsigned long int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_unsigned_long_int_to_file(FILE *f, unsigned long int num, enum file_write_flags flags);
+
+/**
+ * @brief Write int to path.
+ *
+ * @param path File path.
+ * @param num int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_unsigned_long_int_to_path(const char *path, unsigned long int num, enum file_write_flags flags);
+
+/**
+ * @brief Write long long int to FILE.
+ *
+ * @param f File pointer
+ * @param num long long int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_long_long_int_to_file(FILE *f, long long int num, enum file_write_flags flags);
+
+/**
+ * @brief Write int to path.
+ *
+ * @param path File path.
+ * @param num int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_long_long_int_to_path(const char *path, long long int num, enum file_write_flags flags);
+
+/**
+ * @brief Write unsigned long long int to FILE.
+ *
+ * @param f File pointer
+ * @param num unsigned long long int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_unsigned_long_long_int_to_file(FILE *f, unsigned long long int num, enum file_write_flags flags);
+
+/**
+ * @brief Write int to path.
+ *
+ * @param path File path.
+ * @param num int to write.
+ * @param flags Optional flags to write file. if
+ * ::FILE_WRITE_NEWLINE_IF_NOT is set, line-end added. For detail, see
+ * ::file_write_flags.
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int write_unsigned_long_long_int_to_path(const char *path, unsigned long long int num, enum file_write_flags flags);
+
+/**
* @brief Read the first line from FILE
*
* @param f File pointer.
@@ -580,6 +736,126 @@ int read_uint64_from_file(FILE *f, uint64_t *u);
* @return 0 on success, -errno on failure.
*/
int read_uint64_from_path(const char *path, uint64_t *u);
+
+/**
+ * @brief Read type int from FILE
+ *
+ * @param f File pointer.
+ * @param num type int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_int_from_file(FILE *f, int *num);
+
+/**
+ * @brief Read type int from path
+ *
+ * @param path File path.
+ * @param num type int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_int_from_path(const char *path, int *num);
+
+/**
+ * @brief Read type unsigned int from FILE
+ *
+ * @param f File pointer.
+ * @param num type unsigned int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_unsigned_int_from_file(FILE *f, unsigned int *num);
+
+/**
+ * @brief Read type unsigned int from path
+ *
+ * @param path File path.
+ * @param num type unsigned int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_unsigned_int_from_path(const char *path, unsigned int *num);
+
+/**
+ * @brief Read type long int from FILE
+ *
+ * @param f File pointer.
+ * @param num type long int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_long_int_from_file(FILE *f, long int *num);
+
+/**
+ * @brief Read type long int from path
+ *
+ * @param path File path.
+ * @param num type long int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_long_int_from_path(const char *path, long int *num);
+
+/**
+ * @brief Read type unsigned long int from FILE
+ *
+ * @param f File pointer.
+ * @param num type unsigned long int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_unsigned_long_int_from_file(FILE *f, unsigned long int *num);
+
+/**
+ * @brief Read type unsigned long int from path
+ *
+ * @param path File path.
+ * @param num type unsigned long int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_unsigned_long_int_from_path(const char *path, unsigned long int *num);
+
+/**
+ * @brief Read type long long int from FILE
+ *
+ * @param f File pointer.
+ * @param num type long long int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_long_long_int_from_file(FILE *f, long long *num);
+
+/**
+ * @brief Read type long long int from path
+ *
+ * @param path File path.
+ * @param num type long long int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_long_long_int_from_path(const char *path, long long *num);
+
+/**
+ * @brief Read type unsigned long long int from FILE
+ *
+ * @param f File pointer.
+ * @param num type unsigned long long int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_unsigned_long_long_int_from_file(FILE *f, unsigned long long *num);
+
+/**
+ * @brief Read type unsigned long long int from path
+ *
+ * @param path File path.
+ * @param num type unsigned long long int pointer
+ *
+ * @return 0 on success, -errno on failure.
+ */
+int read_unsigned_long_long_int_from_path(const char *path, unsigned long long *num);
/**
* @}
*/