Xively C library

Dependents:   xively-jumpstart-demo

This is Xively C library, the code lives on GitHub.

See our example program and the tutorial, documentation can bee found here.

Committer:
xively
Date:
Mon May 13 19:28:22 2013 +0000
Revision:
0:53753690a8bf
libxively v0.1.1-rc0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
xively 0:53753690a8bf 1 // Copyright (c) 2003-2013, LogMeIn, Inc. All rights reserved.
xively 0:53753690a8bf 2 // This is part of Xively C library, it is under the BSD 3-Clause license.
xively 0:53753690a8bf 3
xively 0:53753690a8bf 4 /**
xively 0:53753690a8bf 5 * \file xi_helpers.h
xively 0:53753690a8bf 6 * \author Olgierd Humenczuk
xively 0:53753690a8bf 7 * \brief General helpers used by the library
xively 0:53753690a8bf 8 */
xively 0:53753690a8bf 9
xively 0:53753690a8bf 10 #ifndef __XI_HELPERS_H__
xively 0:53753690a8bf 11 #define __XI_HELPERS_H__
xively 0:53753690a8bf 12
xively 0:53753690a8bf 13 #include <stdlib.h>
xively 0:53753690a8bf 14 #include <time.h>
xively 0:53753690a8bf 15 #include <limits.h>
xively 0:53753690a8bf 16
xively 0:53753690a8bf 17 #ifdef __cplusplus
xively 0:53753690a8bf 18 extern "C" {
xively 0:53753690a8bf 19 #endif
xively 0:53753690a8bf 20
xively 0:53753690a8bf 21 /**
xively 0:53753690a8bf 22 * \note Needed to avoid using `strdup()` which can cause some problems with `free()`,
xively 0:53753690a8bf 23 * because of buggy `realloc()` implementations.
xively 0:53753690a8bf 24 *
xively 0:53753690a8bf 25 * \return Duplicated string or null in case of memory allocation problem.
xively 0:53753690a8bf 26 */
xively 0:53753690a8bf 27 char* xi_str_dup( const char* s );
xively 0:53753690a8bf 28
xively 0:53753690a8bf 29 /**
xively 0:53753690a8bf 30 * \brief Copies `src` string into `dst`, but stops whenever `delim` is reached or the `dst_size` is exceeded
xively 0:53753690a8bf 31 *
xively 0:53753690a8bf 32 * \return Number of copied characters or -1 if an error occurred.
xively 0:53753690a8bf 33 */
xively 0:53753690a8bf 34 int xi_str_copy_untiln( char* dst, size_t dst_size, const char* src, char delim );
xively 0:53753690a8bf 35
xively 0:53753690a8bf 36 /**
xively 0:53753690a8bf 37 * \brief Converts from `tm` to `time_t`
xively 0:53753690a8bf 38 *
xively 0:53753690a8bf 39 * \note This code assumes that unsigned long can be converted to `time_t`.
xively 0:53753690a8bf 40 * A `time_t` should not be wider than `unsigned long`, since this
xively 0:53753690a8bf 41 * would mean that the check for overflow at the end could fail.
xively 0:53753690a8bf 42 *
xively 0:53753690a8bf 43 * \note This implementation had been copied from MINIX C library.
xively 0:53753690a8bf 44 * Which is 100% compatible with our license.
xively 0:53753690a8bf 45 *
xively 0:53753690a8bf 46 * \note This function does not take into account the timezone or the `dst`,
xively 0:53753690a8bf 47 * it just converts `tm` structure using date and time fields (i.e. UTC).
xively 0:53753690a8bf 48 */
xively 0:53753690a8bf 49 time_t xi_mktime( struct tm* t );
xively 0:53753690a8bf 50
xively 0:53753690a8bf 51 /**
xively 0:53753690a8bf 52 * \brief This just wraps system's `gmtime()`, it a facade for future use
xively 0:53753690a8bf 53 */
xively 0:53753690a8bf 54 struct tm* xi_gmtime( time_t* t );
xively 0:53753690a8bf 55
xively 0:53753690a8bf 56 /**
xively 0:53753690a8bf 57 * \brief Replaces `p` with `r` for every `p` in `buffer`
xively 0:53753690a8bf 58 *
xively 0:53753690a8bf 59 * \return Pointer to converted buffer.
xively 0:53753690a8bf 60 * \note This function assumes that the buffer is terminated with `\0`.
xively 0:53753690a8bf 61 */
xively 0:53753690a8bf 62 char* xi_replace_with(
xively 0:53753690a8bf 63 char p, char r
xively 0:53753690a8bf 64 , char* buffer
xively 0:53753690a8bf 65 , size_t max_chars );
xively 0:53753690a8bf 66
xively 0:53753690a8bf 67 #ifdef __cplusplus
xively 0:53753690a8bf 68 }
xively 0:53753690a8bf 69 #endif
xively 0:53753690a8bf 70
xively 0:53753690a8bf 71 #endif // __XI_HELPERS_H__