static void testValid(void) { int err; const char *src; DaDesc desc; DaStruct *da; desc.elements = 10; desc.bytesPerElement = 1; da = daCreate(&desc, &err); sput_fail_if(da == NULL, "Unable to create dynamic array."); sput_fail_if(daClear(da, &err, DA_FAST) != 0, "daClear should succeed if we clear fast"); sput_fail_if(err != DA_OK, "err != DA_OK"); sput_fail_if(da->used != 0, "daClear should reset the used counter"); src = "5555555555"; memcpy(da->firstAddr, src, 10); da->used = 10; sput_fail_if(daClear(da, &err, DA_SECURE) != 0, "daClear should succeed if we clear fast"); sput_fail_if(err != DA_OK, "err != DA_OK"); sput_fail_if(da->used != 0, "daClear should reset the used counter"); src = "0000000000"; sput_fail_if(memcmp(da->firstAddr, src, 10) != 0, "daClear in secure mode doesn't erase the array content"); daDestroy(da, &err); }
void lbmRendererStartup() { WNDCLASS wndClass; wndClass.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; wndClass.lpfnWndProc = lbmRendererWndProc; wndClass.cbClsExtra = 0; wndClass.cbWndExtra = 0; wndClass.hInstance = GetModuleHandle(NULL); wndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION); wndClass.hCursor = LoadCursor(NULL, IDC_ARROW); wndClass.hbrBackground = GetStockObject(BLACK_BRUSH); wndClass.lpszMenuName = NULL; wndClass.lpszClassName = sClassName; RegisterClass(&wndClass); daCreate(&sUpdates, sizeof(lbmUpdateInfo)); }
DynArray * strSplit(char delimiter, char * str) { if(str == NULL) { return NULL; } // Creating array DynArray * array = daCreate(); // Copying buffer. Maximal size of result is length of string str (including // 0-determinant). char * buffer = malloc((strlen(str) + 1) * sizeof(char)); // Current index (in str string). int index = 0; for(int i = 0; i < strlen(str); i++) { if(str[i] != delimiter) { // Add char to the buffer. buffer[index++] = str[i]; } // If this end of string or delimiter was found and length of // buffer != 0 add new string to the array. if((i == strlen(str) - 1 || str[i] == delimiter) && index != 0) { // Add 0 determinant. buffer[index] = '\0'; // Save buffer contents to new string. char * new_str = malloc((strlen(buffer) + 1) * sizeof(char)); memcpy(new_str, buffer, sizeof(char) * (strlen(buffer) + 1)); // Add string to the array. daPrepend(array, new_str); index = 0; } } // Free buffer. free(buffer); return array; }
DynArray* ssp (unsigned int r, unsigned int c, Map *map) { DynArray * da = daCreate(); for(int i = 0; i < map -> max_r; i++) { // iaLengthCreate() creates array with length c and this array is // already null'd (each element == 0). So there is no need in it's // initialization. IntArray * row = iaCreate(); for (int j = 0; j < map -> max_r; j++) { iaPrepend(row, -1); } // Prepend row. daPrepend(da, row); } setCell(da,r,c,map); return da; }