This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
tsmpipe/lib/dsmobjects.c

144 lines
2.5 KiB
C
Raw Normal View History

2013-07-18 13:59:14 +00:00
/*
* Date manipulations functions for tsmpipe
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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,int verbose) {
dsmDate *date;
dsUint32_t x;
date = (dsmDate*)malloc(sizeof(dsmDate));
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') {
x = atol(s);
date->month = x / 1000000;
x %= 1000000;
date->day = x / 10000;
date->year = x % 10000;
}
if (verbose)
printf("dsmStrToDate: date = %d, month = %d, year = %d\n", date->day, date->month, date->year);
return *date;
}
/* Display the dsmDate value as a string */
char *dsmDateToStr(dsmDate date) {
char *s;
s = malloc(19);
if (s==NULL) {
perror("Arg, out of memory?");
exit(255);
}
memset(s,0x00,sizeof(s));
sprintf(s,"%02i/%02i/%04i %02i:%02i:%02i",
(dsInt16_t)date.day,
(dsInt16_t)date.month,
date.year,
(dsInt16_t)date.hour,
(dsInt16_t)date.minute,
(dsInt16_t)date.second);
return s;
}
dsmObjName dsmNameToObjname(char *fsname, char *filename, 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,"dsmNameToObjname: FS: %s Filename: %s\n",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(s));
sprintf(s,"%s%s%s",objName.fs,objName.hl,objName.ll);
return s;
}
double dsmSizeToNum(dsStruct64_t dsStruct64) {
unsigned long long filesize=0;
filesize = 0x00;
filesize = dsStruct64.hi;
filesize <<= 32;
filesize |= dsStruct64.lo;
// Return number in MB
return (float)filesize/1024/1024;
}