text stringlengths 0 357 |
|---|
size_t i, cnt = array->count; |
for (i=0; i<cnt; i++) |
{ |
if (data[i]==needle) { |
if (ret_index) { |
*ret_index = i; |
} |
return 1; |
} |
} |
return 0; |
} |
/** |
* Get raw pointer to the data. |
* |
* @memberof dc_array_t |
* @param array The array object. |
* @return Raw pointer to the array. You MUST NOT free the data. You MUST NOT access the data beyond the current item count. |
* It is not possible to enlarge the array this way. Calling any other dc_array*()-function may discard the returned pointer. |
*/ |
const uintptr_t* dc_array_get_raw(const dc_array_t* array) |
{ |
if (array==NULL || array->magic!=DC_ARRAY_MAGIC) { |
return NULL; |
} |
return array->array; |
} |
char* dc_arr_to_string(const uint32_t* arr, int cnt) |
{ |
/* return comma-separated value-string from integer array */ |
char* ret = NULL; |
const char* sep = ","; |
if (arr==NULL || cnt <= 0) { |
return dc_strdup(""); |
} |
/* use a macro to allow using integers of different bitwidths */ |
#define INT_ARR_TO_STR(a, c) { \ |
int i; \ |
ret = malloc((c)*(11+strlen(sep))/*sign,10 digits,sep*/+1/*terminating zero*/); \ |
if (ret==NULL) { exit(35); } \ |
ret[0] = 0; \ |
for (i=0; i<(c); i++) { \ |
if (i) { \ |
strcat(ret, sep); \ |
} \ |
sprintf(&ret[strlen(ret)], "%lu", (unsigned long)(a)[i]); \ |
} \ |
} |
INT_ARR_TO_STR(arr, cnt); |
return ret; |
} |
char* dc_array_get_string(const dc_array_t* array, const char* sep) |
{ |
char* ret = NULL; |
if (array==NULL || array->magic!=DC_ARRAY_MAGIC || sep==NULL) { |
return dc_strdup(""); |
} |
INT_ARR_TO_STR(array->array, array->count); |
return ret; |
} |
``` |
Filename: dc_chat.c |
```c |
#include <assert.h> |
#include "dc_context.h" |
#include "dc_job.h" |
#include "dc_smtp.h" |
#include "dc_imap.h" |
#include "dc_mimefactory.h" |
#include "dc_apeerstate.h" |
#define DC_CHAT_MAGIC 0xc4a7c4a7 |
/** |
* Create a chat object in memory. |
* |
* @private @memberof dc_chat_t |
* @param context The context that should be stored in the chat object. |
* @return New and empty chat object, must be freed using dc_chat_unref(). |
*/ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.