/* * Date manipulations functions for tsmpipe */ #include #include #include #include "dsmapitd.h" /* * This function will take a string date entered and convert that to a TSM * date * * The date is passed to this function in the format mmddYYYY */ dsmDate dsmStrToDate(char *s) { extern int verbose; dsmDate *date; dsUint32_t d,t; char *x=NULL, *y=NULL; date = (dsmDate*)malloc(sizeof(dsmDate)); x = (char *)malloc(sizeof(s)); y = (char *)malloc(sizeof(s)); if (date==NULL) { perror("Arg, out of memory?"); exit(255); } memset(date,0x00,sizeof(dsmDate)); if (verbose) printf("dsmStrToDate: Date String: %s\n", s); /* if user key in some inputs */ if (s[0] != '\0') { y=strchr(s,':'); if (y != NULL) { strncpy(x,s,strlen(s)-strlen(y)); x[strlen(s)-strlen(y)] = '\0'; y = strchr(s,':')+1; } else x = s; d = atol(x); date->month = d / 1000000; d %= 1000000; date->day = d / 10000; date->year = d % 10000; if (y != NULL) { t = atol(y); date->hour = t / 10000; t %= 10000; date->minute = t / 100; date->second = t % 100; } } if (verbose) printf("dsmStrToDate: date = %d, month = %d, year = %d, hour = %d, minute = %d, second = %d\n", date->day, date->month, date->year, date->hour, date->minute, date->second); return *date; } /* Display the dsmDate value as a string */ char *dsmDateToStr(dsmDate date) { char *s; int s_size = 32; s = malloc(s_size); if (s==NULL) { perror("Arg, out of memory?"); exit(255); } memset(s,0x00,s_size); sprintf(s,"%04i-%02i-%02i %02i:%02i:%02i", date.year, (dsInt16_t)date.month, (dsInt16_t)date.day, (dsInt16_t)date.hour, (dsInt16_t)date.minute, (dsInt16_t)date.second); return s; } dsmObjName dsmNameToObjname(char *fsname, char *filename) { extern int verbose; dsmObjName *objname; char *p; objname = (dsmObjName*)malloc(sizeof(dsmObjName)); if (objname==NULL) { perror("Arg, out of memory?"); exit(255); } memset(objname,0x00,sizeof(dsmObjName)); if (verbose) fprintf(stderr,"%s: FS: %s Filename: %s\n",__func__,fsname,filename); /* fs == "/filesystem", hl == "/directory/path", ll == "/filename" */ strcpy(objname->fs,fsname); p = strrchr(filename, '/'); if (p) { *p = '\0'; if (*filename && *filename != '/') strcpy(objname->hl, "/"); strcpy(objname->hl,filename); sprintf(objname->ll,"/%s",p+1); } else { if (*filename && *filename != '/') strcpy(objname->ll, "/"); strcat(objname->ll,filename); } objname->objType = DSM_OBJ_FILE; return *objname; } char *dsmObjnameToStr(dsmObjName objName) { char *s; s = malloc(sizeof(dsmObjName)); if (s==NULL) { perror("Arg, out of memory?"); exit(255); } memset(s,0x00,sizeof(dsmObjName)); sprintf(s,"%s%s%s",objName.fs,objName.hl,objName.ll); return s; } double dsmSizeToNum(dsStruct64_t dsStruct64,dsBool_t inMB) { unsigned long long filesize; extern int verbose; filesize = dsStruct64.hi; filesize <<= 32; filesize |= dsStruct64.lo; if (verbose) fprintf(stderr,"%s: Size: %d\n",__func__,(int)filesize); // Return number in MB return inMB ? (double)filesize/1024/1024 : (double)filesize; } void debugLog(int level, const char *func, char *message, int die) { extern int verbose; if (level > verbose) return; fprintf(stderr,"%s: %s\n",func,message); if (die) exit(die); }