CuFile *pp_create_file(const char *controlpath){ CuFile *file; PPfile *ppfile; /* get file structure */ file = CuCreateFile(CuPP); if (file == (CuFile*)0) goto err1; /* allocate internal structure - hang it off cu_file structure */ ppfile=pp_malloc(sizeof(PPfile), NULL); if (ppfile==NULL) goto err2; file->internp = ppfile; ppfile->fh = NULL; strncpy(file->controlpath, controlpath, CU_MAX_PATH); ppfile->landmask = NULL; ppfile->store_raw_headers = 0; ppfile->basetime = 0; /* initialise heap list */ ppfile->heaplist = pp_list_new(NULL); if (ppfile->heaplist == NULL) goto err3; return file; err3: pp_free(ppfile,NULL); err2: CuDeleteFile(file->id); err1: pp_error("pp_create_file"); return NULL; }
int to_TimeInternal(TimeInternal *internal, Timestamp *external) { /* Program will not run after 2038... */ if (external->secondsField.lsb < INT_MAX) { internal->seconds = external->secondsField.lsb; internal->nanoseconds = external->nanosecondsField; return 0; } else { pp_error("to_TimeInternal: " "seconds field is higher than signed integer (32bits)\n"); return -1; } }
int pp_check_sizes() { if (sizeof(Freal4) != 4 || sizeof(Freal8) != 8 || sizeof(Fint4) != 4 || sizeof(Fint8) != 8 || sizeof(Fint) != sizeof (Freal) || cutypelen(inttype) != sizeof(Fint) || cutypelen(realtype) != sizeof(Freal)) { pp_error("pp_check_sizes"); return -1; } return 0; }
int from_TimeInternal(TimeInternal *internal, Timestamp *external) { /* * fromInternalTime is only used to convert time given by the system * to a timestamp As a consequence, no negative value can normally * be found in (internal) * * Note that offsets are also represented with TimeInternal structure, * and can be negative, but offset are never convert into Timestamp * so there is no problem here. */ if ((internal->seconds & ~INT_MAX) || (internal->nanoseconds & ~INT_MAX)) { pp_error("Negative value cannot be converted into " "timestamp\n"); return -1; } else { external->secondsField.lsb = internal->seconds; external->nanosecondsField = internal->nanoseconds; external->secondsField.msb = 0; } return 0; }
void cField_to_TimeInternal(TimeInternal *internal, Integer64 cField) { uint64_t i64; i64 = cField.lsb; i64 |= ((int64_t)cField.msb) << 32; if ((int32_t)cField.msb < 0) pp_error("BUG: %s doesn't support negatives\n", __func__); /* * the correctionField is nanoseconds scaled by 16 bits. * It is updated by transparent clocks and may be used to count * for asymmetry. Since we support no better than nanosecond with * the standard protocol and WR (which is better than nanosecond) * doesn't use this field, just approximate to nanoseconds. * and the WR extension uses its own methods for asymmetry, */ i64 += 0x8000; i64 >>= 16; /* Use __div64_32 from library, to avoid libgcc on small targets */ internal->nanoseconds = __div64_32(&i64, PP_NSEC_PER_SEC); internal->seconds = i64; }