Xively C library

Dependents:   Application-xively-jumpstart-demo Application-xively-jumpstart-demo Modified_Xively_Jumpstart HW7-1_Xively_Thermostat

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:
Wed Jun 26 10:40:43 2013 +0000
Revision:
0:82702e998d3f
libxively v0.1.1-rc0 (34c8b32)

Who changed what in which revision?

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