void traverse(char *dirPath) // IN: Directory Path { DIR* FD; FILE* op; struct dirent* in_file; char path[MAX_FILE_NAME_LEN]; int len; Str_Strcpy(path, dirPath, MAX_FILE_NAME_LEN); len = (int) strlen(dirPath); path[len++] = '/'; FD = opendir(dirPath); if (FD == NULL){ printf("Error : Failed to open input directory\n"); return; } op = fopen(DST, "wb"); if(op == NULL){ printf("Failed to open file %s \n", DST); return; } fprintf(op, "File Name,md5,offset,size\n"); //Print header for file while ((in_file = readdir(FD))){ if (!strcmp(in_file->d_name, ".")) continue; if (!strcmp(in_file->d_name, "..")) continue; Str_Strcpy(path + len, in_file->d_name, MAX_FILE_NAME_LEN - len); printf("Path is %s\n", path); generateDedupDump(path, op); } if(fclose(op) != 0){ printf("Error closing file %s\n", DST); return; } if(closedir(FD) == -1){ printf("Error closing directory\n"); return; } return; }
static void StrUtilRemoveListItem(char * const list, // IN/OUT: char delim, // IN: char const *item, // IN: int (*cmp)(char const*, char const*)) // IN: { char *tok; char *work = list; int maxSize = strlen(list) + 1; while ((tok = StrUtil_GetNextItem(&work, delim)) != NULL) { if (cmp(tok, item) == 0) { // found the item if (work != NULL) { // in the middle of the list // overwrite it with the rest of the list Str_Strcpy(tok, work, maxSize); } else if (tok == list) { tok[0] = '\0'; // only item in the list } else { tok[-1] = '\0'; // or the last element in the list } return; } else if (work != NULL) { // restore delimiter that was replaced by Str_GetNextItem work[-1] = delim; } } }
Bool TimeUtil_StringToDate(TimeUtil_Date *d, // IN/OUT char const *date) // IN { /* * Reduce the string to a known and handled format: YYYYMMDD. * Then, passed to internal function TimeUtilLoadDate. */ if (strlen(date) == 8) { /* 'YYYYMMDD' */ return TimeUtilLoadDate(d, date); } else if (strlen(date) == 10) { /* 'YYYY/MM/DD' */ char temp[16] = { 0 }; if (!(((date[4] != '/') || (date[7] != '/')) || ((date[4] != '-') || (date[7] != '-')))) { return FALSE; } Str_Strcpy(temp, date, sizeof(temp)); temp[4] = date[5]; temp[5] = date[6]; temp[6] = date[8]; temp[7] = date[9]; temp[8] = '\0'; return TimeUtilLoadDate(d, temp); } else { return FALSE; } }
static int getHostPairCallback(void *pArg, int nArg, char **azArg, char **azCol) { HostIdRecord *hr = pArg; int numIds = hr->numIds++; LogFS_HashSetString(&hr->hostIds[numIds], azArg[0]); hr->hostNames[numIds] = malloc(256); Str_Strcpy(hr->hostNames[numIds], azArg[1],100); return 0; }
void GuestInfoConvertNicInfoToNicInfoV1(NicInfoV3 *info, GuestNicInfoV1 *infoV1) { uint32 maxNics; u_int i; ASSERT(info); ASSERT(infoV1); maxNics = MIN(info->nics.nics_len, MAX_NICS); infoV1->numNicEntries = maxNics; if (maxNics < info->nics.nics_len) { g_debug("Truncating NIC list for backwards compatibility.\n"); } XDRUTIL_FOREACH(i, info, nics) { u_int j; uint32 maxIPs; GuestNicV3 *nic = XDRUTIL_GETITEM(info, nics, i); Str_Strcpy(infoV1->nicList[i].macAddress, nic->macAddress, sizeof infoV1->nicList[i].macAddress); maxIPs = MIN(nic->ips.ips_len, MAX_IPS); infoV1->nicList[i].numIPs = 0; XDRUTIL_FOREACH(j, nic, ips) { IpAddressEntry *ip = XDRUTIL_GETITEM(nic, ips, j); TypedIpAddress *typedIp = &ip->ipAddressAddr; if (typedIp->ipAddressAddrType != IAT_IPV4) { continue; } if (NetUtil_InetNToP(AF_INET, typedIp->ipAddressAddr.InetAddress_val, infoV1->nicList[i].ipAddress[j], sizeof infoV1->nicList[i].ipAddress[j])) { infoV1->nicList[i].numIPs++; if (infoV1->nicList[i].numIPs == maxIPs) { break; } } }
void RpcVMX_LogSetPrefix(const char *prefix) { size_t prefixLen = strlen(prefix); if (prefixLen + sizeof "log" >= sizeof RpcVMX.logBuf - 1) { /* * Somebody passed a huge prefix. Don't do that! */ RpcVMX.logOffset = sizeof "log"; return; } Str_Strcpy(RpcVMX.logBuf + sizeof "log", prefix, sizeof RpcVMX.logBuf - sizeof "log"); RpcVMX.logOffset = (unsigned int)(sizeof "log" + prefixLen); }
void MXUserHistoDump(MXUserHisto *histo, // IN: MXUserHeader *header) // IN: { ASSERT(header); ASSERT(histo); if (histo->totalSamples) { char *p; uint32 i; uint32 spaceLeft; ASSERT(mxUserHistoLine); i = Str_Sprintf(mxUserHistoLine, mxUserMaxLineLength, "MXUser: h l=%u t=%s min=%"FMT64"u max=%"FMT64"u\n", header->bits.serialNumber, histo->typeName, histo->minValue, histo->maxValue); /* * The terminating "\n\0" will be overwritten each time a histogram * bin is added to the line. This will ensure that the line is always * properly terminated no matter what happens. */ p = &mxUserHistoLine[i - 1]; spaceLeft = mxUserMaxLineLength - i - 2; /* Add as many histogram bins as possible within the line limitations */ for (i = 0; i < histo->numBins; i++) { if (histo->binData[i] != 0) { uint32 len; char binEntry[32]; len = Str_Sprintf(binEntry, sizeof binEntry, " %u-%"FMT64"u\n", i, histo->binData[i]); if (len < spaceLeft) { /* * Append the bin number, bin count pair to the end of the * string. This includes the terminating "\n\0". Update the * pointer to the next free place to point to the '\n'. If * another entry is made, things work out properly. If not * the string is properly terminated as a line. */ Str_Strcpy(p, binEntry, len + 1); p += len - 1; spaceLeft -= len; } else { break; } } } MXUserStatsLog("%s", mxUserHistoLine); i = Str_Sprintf(mxUserHistoLine, mxUserMaxLineLength, "MXUser: ht l=%u t=%s\n", header->bits.serialNumber, histo->typeName); p = &mxUserHistoLine[i - 1]; spaceLeft = mxUserMaxLineLength - i - 2; for (i = 0; i < TOPOWNERS; i++) { if (histo->ownerArray[i].address != NULL) { uint32 len; char binEntry[32]; /* Use a debugger to change the address to a symbol */ len = Str_Sprintf(binEntry, sizeof binEntry, " %p-%"FMT64"u\n", histo->ownerArray[i].address, histo->ownerArray[i].timeValue); if (len < spaceLeft) { /* * Append the address, time value pair to the end of the * string. This includes the terminating "\n\0". Update the * pointer to the next free place to point to the '\n'. If * another entry is made, things work out properly. If not * the string is properly terminated as a line. */ Str_Strcpy(p, binEntry, len + 1); p += len - 1; spaceLeft -= len; } else { break; } } } MXUserStatsLog("%s", mxUserHistoLine); } }
static int getPeerForHostCallback(void *pArg, int nArg, char **azArg, char **azCol) { Str_Strcpy(pArg, azArg[0],100); return 0; }
static int getSingleValueCallback(void *pArg, int nArg, char **azArg, char **azCol) { Str_Strcpy(pArg, azArg[0],100); return 0; }