lasErr FUNCTION c_lswrit(FILE **fd, const char *key, int *clen, int *dlen, const char *cbuf, const unsigned char *dbuf, const char *dtype) { FILE *fp; char header[HDRL]; char len[LENL]; fp = *fd; if (strlen(key) >= KEYL) { c_errmsg("Error: Key length too long. Key should be truncated.", "lswrit-key", NON_FATAL); } /*Seek to end-of-file.*/ FSEEK64(*fd, 0, 2); if (*clen > 0) sprintf(len,"%-d/%-d",*clen,*dlen); else sprintf(len,"%-d",*dlen); sprintf (header,"%-*s%-*s%-*s",LENL,len,TYPL,dtype,KEYL-1,key); FWRITE(header,sizeof(char),HDRL,fp); if (*clen > 0) FWRITE(cbuf,sizeof(char), *clen,fp); if (*dlen > 0) FWRITE(dbuf,sizeof(char), *dlen,fp); return(E_SUCC); }
MME_ERROR acc_MME_InitTransformer(const char *Name, MME_TransformerInitParams_t * Params_p, MME_TransformerHandle_t * Handle_p) { MME_ERROR mme_status; FILE * fcmd = cmd_log_lock(); if (log_enable == ACC_TRUE) { FWRITE(cmd_str[CMD_INIT], strlen(cmd_str[CMD_INIT]) + 1, 1, fcmd); FWRITE((char *)Name, strlen(Name) + 1, 1, fcmd); FWRITE(Params_p, sizeof(MME_TransformerInitParams_t), 1, fcmd); FWRITE(Params_p->TransformerInitParams_p, Params_p->TransformerInitParamsSize, 1, fcmd); } cmd_log_release(fcmd); mme_status = MME_InitTransformer(Name, Params_p, Handle_p); if (log_enable) { if (mme_status == MME_SUCCESS) handles[handles_new()] = (int) *Handle_p; } return mme_status; }
MME_ERROR acc_MME_GetTransformerCapability(const char *TransformerName, MME_TransformerCapability_t *TransformerInfo_p) { if (log_enable == ACC_TRUE) { FILE *fcmd = cmd_log_lock(); FWRITE(cmd_str[CMD_GETCAPABILITY], strlen(cmd_str[CMD_GETCAPABILITY]) + 1, 1, fcmd); FWRITE((char *)TransformerName, strlen((char *)TransformerName) + 1, 1, fcmd); cmd_log_release(fcmd); } return MME_GetTransformerCapability(TransformerName, TransformerInfo_p); }
MME_ERROR acc_MME_AbortCommand(MME_TransformerHandle_t Handle, MME_CommandId_t CmdId) { if (log_enable == ACC_TRUE) { FILE *fcmd = cmd_log_lock(); int hdl_idx = handles_search(Handle); FWRITE(cmd_str[CMD_ABORT], strlen(cmd_str[CMD_ABORT]) + 1, 1, fcmd); FWRITE(&hdl_idx, sizeof(int), 1, fcmd); FWRITE(&CmdId, sizeof(int), 1, fcmd); cmd_log_release(fcmd); } return MME_AbortCommand(Handle, CmdId); }
void write_string_table( void ) { long t = 0; if( string_table_index > 4 ) t = string_table_index; fseek( obj_fd, 0L, 2 ); FWRITE( &t, sizeof(long), 1, obj_fd ); #ifdef MSDOS FWRITE( &string_table[4], sizeof(char), (size_t) (string_table_index - 4), obj_fd ); #else FWRITE( &string_table[4], sizeof(char), (string_table_index - 4), obj_fd ); #endif }
static int met_save_para(U8 bForce) { if(met_mem.bModify) { if(met_mem.nChkSec==1 || met_mem.nChkCnt==1 || bForce) { FHANDLE fp; fp=FOPEN("met.bin","w"); if(fp==NULL)fp=FOPEN("met.bin","wb"); if(fp) { //FSEEK(fp,met_mem.met*MET_ITEM_SIZE,SEEK_SET); if(met_mem.pbuf!=NULL) FWRITE(met_mem.pbuf,MET_BUF_SIZE,1,fp); FCLOSE(fp); met_mem.wCnt++; met_mem.bModify=0; } met_mem.nChkSec=0; met_mem.nChkCnt=0; } if(met_mem.nChkSec)met_mem.nChkSec--; } return 1; }
static int sys_save_para(U8 bForce) { if(sys_mem.bModify) { if(sys_mem.nChkSec==1 || sys_mem.nChkCnt==1 || bForce) { FHANDLE fp; fp=FOPEN("sys.bin","w"); //if(fp==NULL)fp=FOPEN("sys.bin","wb"); // 系统出错时会导致丢参数, 2014.2.18去掉 if(fp) { if(sys_mem.pbuf!=NULL) FWRITE(sys_mem.pbuf,SYS_BUF_SIZE,1,fp); FCLOSE(fp); // sys_mem.crc=CHECK_CRC(sys_mem.pbuf,sys_mem.size); sys_mem.wCnt++; sys_mem.bModify=0; // return 1; } sys_mem.nChkSec=0; sys_mem.nChkCnt=0; } if(sys_mem.nChkSec)sys_mem.nChkSec--; // if(sys_mem.nChkCnt)sys_mem.nChkCnt--; } return 1; }
int AFfWrMulaw (AFILE *AFp, const float Dbuff[], int Nval) { int is, N, Nw, i; UT_uint1_t Buf[NBBUF/LW]; double Dv; /* Write data to the audio file */ is = 0; while (is < Nval) { N = MINV (NBBUF / LW, Nval - is); for (i = 0; i < N; ++i) { Dv = AFp->ScaleF * Dbuff[i+is]; if (Dv > AMAX || Dv < -AMAX) ++AFp->Novld; Buf[i] = Yq[SPdQuantL (Dv, Xq, NLEV)]; } Nw = FWRITE (Buf, LW, N, AFp->fp); is += Nw; if (Nw < N) break; } return is; }
void save_window_to_file(char *filename, int w , int h) { int i; int linesize=3*w*sizeof(char); char *buffer = (char *) malloc (h*linesize); char *buffer2 = (char*) malloc (h*linesize); FILE *file; glPixelStorei (GL_PACK_ALIGNMENT, 1); glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, buffer); /* invert the order of the lines */ for (i=0; i<h; i++) { memcpy(buffer2+linesize*i,buffer+linesize*(h-1-i),linesize); } file = fopen (filename, "wb"); fprintf (file, "P6 %d %d 255\n", w, h); FWRITE (buffer2, sizeof(GLubyte), w * h * 3, file); fclose (file); free(buffer); free(buffer2); }
void log_status_skip(LogInstance instance, const gchar *format, ...) { va_list args; gchar buf[BUFFSIZE + LOG_TIME_LEN]; time_t t; LogText *logtext = g_new0(LogText, 1); struct tm buft; time(&t); strftime(buf, LOG_TIME_LEN + 1, "[%H:%M:%S] ", localtime_r(&t, &buft)); va_start(args, format); g_vsnprintf(buf + LOG_TIME_LEN, BUFFSIZE, format, args); va_end(args); if (debug_get_mode()) g_message("%s", buf + LOG_TIME_LEN); logtext->instance = instance; logtext->text = g_strdup(buf + LOG_TIME_LEN); logtext->type = LOG_STATUS_SKIP; g_timeout_add(0, invoke_hook_cb, logtext); if (log_fp[instance] && prefs_common_enable_log_status()) { FWRITE(buf, 1, LOG_TIME_LEN, log_fp[instance]) FPUTS("* SKIPPED: ", log_fp[instance]) log_size[instance] += strlen("* SKIPPED: "); FPUTS(buf + LOG_TIME_LEN, log_fp[instance]) log_size[instance] += strlen(buf); FFLUSH(log_fp[instance]) rotate_log(instance); } }
/*Write the binary PCM frames to the given file*/ void JRS_PCM_write(JRS_PCM *p,const char *fName) { FILE *f=FOPEN(fName,"wb"); int i; for (i=0;i<p->nFrames;i++) FWRITE(&p->frames[i*128],128,1,f); FCLOSE(f); asfPrintStatus("Wrote %d 128-byte frames of JRS PCM data to '%s'.\n",p->nFrames,fName); }
int AFfWrI3 (AFILE *AFp, const float Dbuff[], int Nval) { int is, N, Nw, i, j, Hbo; UT_int4_t Iv; unsigned char Buf[NBBUF]; double g, Dv; unsigned char *cp; /* Write data to the audio file */ Hbo = UTbyteOrder (); cp = (unsigned char *) &Iv; is = 0; g = AFp->ScaleF; while (is < Nval) { N = MINV (NBBUF / LW3, Nval - is); for (i = 0, j = is; i < LW3*N; i += LW3, ++j) { Dv = g * Dbuff[j]; if (Dv >= 0.0) { Dv += 0.5; if (Dv >= UT_INT3_MAX + 1) { ++AFp->Novld; Dv = UT_INT3_MAX; } } else { Dv += -0.5; if (Dv <= UT_INT3_MIN - 1) { ++AFp->Novld; Dv = UT_INT3_MIN; } } if (Hbo == DS_EL) Iv = (UT_int4_t) Dv; /* DS_EL: X 2 1 0 */ else /* MSB LSB */ Iv = 256 * ((UT_int4_t) Dv); /* DS_EB: 0 1 2 X */ if (AFp->Swapb == DS_SWAP) { Buf[i] = cp[2]; Buf[i+1] = cp[1]; Buf[i+2] = cp[0]; } else { Buf[i] = cp[0]; Buf[i+1] = cp[1]; Buf[i+2] = cp[2]; } } Nw = FWRITE (Buf, LW3, N, AFp->fp); is += Nw; if (Nw < N) break; } return is; }
/* MME_TermTransformer() * Terminate a transformer instance */ MME_ERROR acc_MME_TermTransformer(MME_TransformerHandle_t handle) { MME_ERROR mme_status; int hdl_idx = handles_search(handle); if (log_enable == ACC_TRUE) { FILE *fcmd = cmd_log_lock(); FWRITE(cmd_str[CMD_TERM], strlen(cmd_str[CMD_TERM]) + 1, 1, fcmd); FWRITE(&hdl_idx, sizeof(int), 1, fcmd); cmd_log_release(fcmd); } mme_status = MME_TermTransformer(handle); if (log_enable == ACC_TRUE) { if (mme_status == MME_SUCCESS) handles[hdl_idx] = 0; } return mme_status; }
MME_ERROR acc_MME_SendCommand(MME_TransformerHandle_t Handle, MME_Command_t *CmdInfo_p) { MME_ERROR mme_status; FILE *fcmd = NULL; int i, j, nbuf; if (log_enable == ACC_TRUE) { // log the command; int hdl_idx = handles_search(Handle); fcmd = cmd_log_lock(); FWRITE(cmd_str[CMD_SEND], strlen(cmd_str[CMD_SEND]) + 1, 1, fcmd); FWRITE(&hdl_idx, sizeof(int), 1, fcmd); FWRITE(CmdInfo_p, sizeof(MME_Command_t), 1, fcmd); FWRITE(CmdInfo_p->Param_p, CmdInfo_p->ParamSize, 1, fcmd); // printk("Param: %d\n", ((int*)CmdInfo_p->Param_p)[2]); nbuf = CmdInfo_p->NumberInputBuffers + CmdInfo_p->NumberOutputBuffers; for (i = 0; i < nbuf; i++) { MME_DataBuffer_t *db = CmdInfo_p->DataBuffers_p[i]; MME_ScatterPage_t *sc; FWRITE(db, sizeof(MME_DataBuffer_t), 1, fcmd); if (db->NumberOfScatterPages == 0) { // check whether a buffer is sent without any pages !! should never happen. //acc_warning(ACC_WARNING_NO_SCATTERPAGE_IN_BUFFER); } for (j = 0; j < db->NumberOfScatterPages; j++) { sc = &db->ScatterPages_p[j]; FWRITE(sc, sizeof(MME_ScatterPage_t), 1, fcmd); if (sc->Size != 0) { if (i < CmdInfo_p->NumberInputBuffers) { FWRITE(sc->Page_p, sizeof(unsigned char), sc->Size, fcmd); } } } } } // send the command to get back the ID generated by Multicom mme_status = MME_SendCommand(Handle, CmdInfo_p); if (log_enable == ACC_TRUE) { // replace the ID in the local copy FWRITE(&CmdInfo_p->CmdStatus.CmdId, sizeof(unsigned int), 1, fcmd); cmd_log_release(fcmd); } return mme_status; }
size_t awrite(const void *src, size_t size) { #ifdef WINDOWS if(buffering) { #ifdef PRE_ALLOCATE if(written > last_extended_to) { myFileSeek(ofile, written + 1000000000, FILE_BEGIN); last_extended_to = written + 1000000000; SetEndOfFile(ofile); myFileSeek(ofile, written, FILE_BEGIN); } #endif written += size; return FWRITE(src, size, ofile); } else { size_t n; if(size > largest_request_pub) abort("Internal error, aread(%d) with largest_request == %d", (int)size, (int)largest_request_pub); memcpy(write_buffer + queued, src, size); queued += size; written += size; n = queued / AIO_MAX_SECTOR_SIZE; size_t wrote = FWRITE(write_buffer, n*AIO_MAX_SECTOR_SIZE, ofile); queued -= n*AIO_MAX_SECTOR_SIZE; memmove(write_buffer, write_buffer + n*AIO_MAX_SECTOR_SIZE, queued); if (wrote != n*AIO_MAX_SECTOR_SIZE) return 0; return size; } #else written += size; return FWRITE(src, size, ofile); #endif }
static size_t printf_fwrite(const void *ptr, size_t size, size_t nitems, FILE *stream) { if ((FILE*)stream == stdout || (FILE*)stream == stderr) { int fd = stream == stdout ? fileno(stdout) : fileno(stderr); int res; do { res = write(fd, ptr, size*nitems); } while (res == -1 && (errno == EAGAIN || errno == EINTR)); if (res == -1) return 0; return res; } return FWRITE(ptr, size, nitems, stream); }
void combine(){ FILE *ip= FOPEN("/tmp/file1", "rb"); FILE *op= FOPEN("/tmp/nextLevel","w"); char *line; char str[MAX_COMBINED_HASH_LEN]; size_t maxLen=MAX_COMBINED_HASH_LEN; char md5str[MD5_DIGEST_LENGTH*2+1]; while(getline(&line,&maxLen,ip)!=-1){ char *token = strtok(line, ","); getMD5(token,md5str,strlen(token)); token = strtok(NULL,","); sprintf(str,"%s,%s",md5str,token); FWRITE(str, "Entry row", op); } return; }
//--------------------------- static int sys_load_para(U16 sno) { static int cnt=0, init = 0x38732560; if(sys_mem.bFlag==0x5A) if(sys_mem.pbuf!=NULL && sys_mem.size <= SYS_BUF_SIZE) { if (++cnt < 100) return 1; cnt = 0; if(sys_mem.crc==CHECK_CRC(sys_mem.pbuf,sys_mem.size)) return 1; } //msg_out("\nLoad sys.bin"); if(sys_mem.pbuf==NULL)sys_mem.pbuf=(U8*)mem_sys;//malloc(SYS_BUF_SIZE); if(sys_mem.pbuf!=NULL) { FHANDLE fp; fp=FOPEN("sys.bin","r"); if(fp) { FREAD(sys_mem.pbuf,SYS_BUF_SIZE,1,fp); FCLOSE(fp); } else { if (init == 0x38732560) // 只允许系统上电时创建文件 { FS_MSG("\nCreate sys.bin"); fp=FOPEN("sys.bin","w"); if(fp) { memset(sys_mem.pbuf,0xFF,SYS_BUF_SIZE); FWRITE(sys_mem.pbuf,SYS_BUF_SIZE,1,fp); FCLOSE(fp); } } } sys_mem.rCnt++; sys_mem.size=SYS_BUF_SIZE; sys_mem.crc=CHECK_CRC(sys_mem.pbuf,sys_mem.size); sys_mem.bFlag=0x5A; sys_mem.met=0; init = 0; return 1; } return 0; }
int AFfWrI4 (AFILE *AFp, const float Dbuff[], int Nval) { int is, N, Nw, i; UT_int4_t Buf[NBBUF/LW4]; double g, Dv; unsigned char *cp; unsigned char t; /* Write data to the audio file */ is = 0; g = AFp->ScaleF; while (is < Nval) { N = MINV (NBBUF / LW4, Nval - is); for (i = 0; i < N; ++i) { Dv = g * Dbuff[i+is]; if (Dv >= 0.0) { Dv += 0.5; if (Dv >= (double) UT_INT4_MAX + 1.) { ++AFp->Novld; Dv = UT_INT4_MAX; } } else { Dv += -0.5; if (Dv <= (double) (UT_INT4_MIN) - 1.) { ++AFp->Novld; Dv = UT_INT4_MIN; } } Buf[i] = (UT_int4_t) Dv; if (AFp->Swapb == DS_SWAP) { cp = (unsigned char *) &Buf[i]; t = cp[3]; cp[3] = cp[0]; cp[0] = t; t = cp[2]; cp[2] = cp[1]; cp[1] = t; } } Nw = FWRITE (Buf, LW4, N, AFp->fp); is += Nw; if (Nw < N) break; } return is; }
static int write_f(void *vfp, char* buf, size_t len) { ASSERT(vfp); #ifdef PUTC_ON_SMALL_WRITES if (len <= 64) { /* Try to optimize writes of small bufs. */ int i; for (i = 0; i < len; i++) if (PUTC(buf[i], (FILE *) vfp) == EOF) return get_error_result(); } else #endif if (FWRITE((void *) buf, sizeof(char), len, (FILE *) vfp) != len) return get_error_result(); return 0; }
bool aclose_write(void) { #ifdef WINDOWS if(buffering) { #ifdef PRE_ALLOCATE if(!CloseHandle(ofile)) return false; ofile = CreateFile(destination_file, GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(ofile == INVALID_HANDLE_VALUE) return false; myFileSeek(ofile, awritten(), SEEK_CUR); SetEndOfFile(ofile); #endif return CloseHandle(ofile) != 0; } else { if(ofile == GetStdHandle(STD_OUTPUT_HANDLE)) { return CloseHandle(ofile) != 0; } else { // write remaining data in queue, round UP to nearest sector size (we may write // too much but file will be trucnated later, below). size_t n = (queued | (AIO_MAX_SECTOR_SIZE - 1)) + 1; FWRITE(write_buffer, n, ofile); if(!CloseHandle(ofile)) return false; ofile = CreateFile(destination_file, GENERIC_WRITE, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(ofile == INVALID_HANDLE_VALUE) return false; myFileSeek(ofile, awritten(), SEEK_CUR); SetEndOfFile(ofile); return CloseHandle(ofile) != 0; } } #else if(ofile != 0) fclose(ofile); return true; #endif }
int deviceConnectHardDiskRemove(const char *fileName) { t_nubitcc count; FILE *image; if (fileName) { image = FOPEN(fileName, "wb"); if (image) { if (!vhdd.connect.flagReadOnly) count = FWRITE((void *) vhdd.connect.pImgBase, sizeof(t_nubit8), vhddGetImageSize, image); vhdd.connect.flagDiskExist = False; FCLOSE(image); } else { return True; } } vhdd.connect.flagDiskExist = False; MEMSET((void *) vhdd.connect.pImgBase, Zero8, vhddGetImageSize); return False; }
size_t fwrite_RawClonePair(const RawClonePair *ary, size_t count, FILE *pOutput) { size_t successfullyWrittenCount = 0; for (size_t i = 0; i < count; ++i) { RawClonePair data = ary[i]; flip_endian(data.left.file); flip_endian(data.left.begin); flip_endian(data.left.end); flip_endian(data.right.file); flip_endian(data.right.begin); flip_endian(data.right.end); size_t c = FWRITE(&data, sizeof(RawClonePair), 1, pOutput); if (c == 0) { break; } ++successfullyWrittenCount; } return successfullyWrittenCount; }
// 真正读写操作在这里,这套系统类似于HMI,也是回调函数 //===================================================================================== static int met_load_para(U16 sno) { if(met_mem.bFlag==0x5A) if(met_mem.pbuf!=NULL && met_mem.size <= MET_BUF_SIZE) if(met_mem.crc==CHECK_CRC(met_mem.pbuf,met_mem.size)) { if(!sno || (met_mem.met<=sno&&sno<(met_mem.met+MET_MAX_ITEM))) return 1; met_save_para(1); } // msg_out("\nLoad met.bin"); if(met_mem.pbuf==NULL)met_mem.pbuf=(U8*)mem_met;//malloc(MET_BUF_SIZE); if(met_mem.pbuf!=NULL) { FHANDLE fp; memset(met_mem.pbuf,0xFF,MET_BUF_SIZE); fp=FOPEN("met.bin","r"); //原来如此 if(fp) { met_mem.met=(sno/MET_MAX_ITEM)*MET_MAX_ITEM; //FSEEK(fp,met_mem.met*MET_ITEM_SIZE,SEEK_SET); FREAD(met_mem.pbuf,MET_BUF_SIZE,1,fp); FCLOSE(fp); } else { //msg_out("\nCreate met.bin"); fp=FOPEN("met.bin","w"); if(fp) { FWRITE(met_mem.pbuf,MET_BUF_SIZE,1,fp); FCLOSE(fp); } } met_mem.rCnt++; met_mem.met=(sno/MET_MAX_ITEM)*MET_MAX_ITEM + 1; met_mem.size=MET_BUF_SIZE; met_mem.crc=CHECK_CRC(met_mem.pbuf,met_mem.size); met_mem.bFlag=0x5A; return 1; } return 0; }
/** Flush output buffer to display **/ int ttflush() { int len; /* Compute length of write */ len = outbuft - outbuf; if (len == 0) return(0); /* Reset buffer position */ outbuft = outbuf; /* Perform write to screen */ FWRITE(mpetermout, outbuf, -len, 0320); #ifdef DEBUG if (ccode() != CCE) { printf("FWRITE fails\n"); } #endif return 0; }
int AFfWrI1 (AFILE *AFp, const float Dbuff[], int Nval) { int is, N, Nw, i; UT_int1_t Buf[NBBUF/LW1]; double g, Dv; /* Write data to the audio file */ is = 0; g = AFp->ScaleF; while (is < Nval) { N = MINV (NBBUF / LW1, Nval - is); for (i = 0; i < N; ++i) { Dv = g * Dbuff[i+is]; if (Dv >= 0.0) { Dv += 0.5; if (Dv >= UT_INT1_MAX + 1) { ++AFp->Novld; Dv = UT_INT1_MAX; } } else { Dv += -0.5; if (Dv <= UT_INT1_MIN - 1) { ++AFp->Novld; Dv = UT_INT1_MIN; } } Buf[i] = (UT_int1_t) Dv; } Nw = FWRITE (Buf, LW1, N, AFp->fp); is += Nw; if (Nw < N) break; } return is; }
void SaveAsJob::doSave() { FILE *dst = MKFOPEN(m_newName, _T("wb")); try { ByteArray buffer; for(m_fileIndex = 0; (m_fileIndex < m_size) && !isInterrupted(); m_fileIndex += buffer.size()) { m_src.getBytes(m_fileIndex, 0x4000, buffer); if(buffer.size()) { FWRITE(buffer.getData(), 1, buffer.size(), dst); } } if(isInterrupted()) { throwException(_T("Save cancelled")); } fclose(dst); dst = NULL; } catch(...) { if(dst) { fclose(dst); } unlink(m_newName); m_ok = false; throw; } }
/******************************************************************************* * Write x number of lines of any data type to file in the data format specified * by the meta structure. It is always written in big endian format. Returns the * amount of samples successfully converted & written. Will not write more lines * than specified in the supplied meta struct. */ static int put_data_lines(FILE *file, meta_parameters *meta, int band_number, int line_number_in_band, int num_lines_to_put, const void *source, int source_data_type) { int ii; /* Sample index. */ int samples_put; /* Number of samples written */ size_t sample_size; /* Sample size in bytes. */ void *out_buffer; /* Buffer of converted data to write. */ int sample_count = meta->general->sample_count; int data_type = meta->general->data_type; int num_samples_to_put = num_lines_to_put * sample_count; int line_number = meta->general->line_count * band_number + line_number_in_band; if ((source_data_type>=COMPLEX_BYTE) && (data_type<=REAL64)) { printf("\nput_data_lines: Cannot put complex data into a simple data file. Exiting.\n\n"); exit(EXIT_FAILURE); } if ((source_data_type<=REAL64) && (data_type>=COMPLEX_BYTE)) { printf("\nput_data_lines: Cannot put simple data into a complex data file. Exiting.\n\n"); exit(EXIT_FAILURE); } // Write out all optical data as byte image. // They don't have a larger dynamic range than that. if (meta->optical) data_type = ASF_BYTE; /* Determine sample size. */ sample_size = data_type2sample_size(data_type); /* Make sure not to make file bigger than meta says it should be */ if (line_number > meta->general->line_count * meta->general->band_count) { printf("\nput_data_lines: Cannot write line %d of band %d in a\n" "file that should be %d lines. Exiting.\n", line_number, band_number, meta->general->line_count * meta->general->band_count); exit(EXIT_FAILURE); } if ((line_number+num_lines_to_put) > meta->general->line_count * meta->general->band_count) { num_samples_to_put = (meta->general->line_count - line_number) * sample_count; } FSEEK64(file, (long long)sample_size*sample_count*line_number, SEEK_SET); out_buffer = MALLOC( sample_size * sample_count * num_lines_to_put ); /* Fill in destination array. */ switch (data_type) { case REAL32: for ( ii=0; ii<num_samples_to_put; ii++ ) { switch (source_data_type) { case ASF_BYTE:((float*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case INTEGER16:((float*)out_buffer)[ii] = ((short int*)source)[ii];break; case INTEGER32:((float*)out_buffer)[ii] = ((int*)source)[ii];break; case REAL32:((float*)out_buffer)[ii] = ((float*)source)[ii];break; case REAL64:((float*)out_buffer)[ii] = ((double*)source)[ii];break; } ieee_big32( ((float*)out_buffer)[ii] ); } break; case COMPLEX_REAL32: for ( ii=0; ii<num_samples_to_put*2; ii++ ) { switch (source_data_type) { case COMPLEX_BYTE:((float*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case COMPLEX_INTEGER16:((float*)out_buffer)[ii] = ((short int*)source)[ii];break; case COMPLEX_INTEGER32:((float*)out_buffer)[ii] = ((int*)source)[ii];break; case COMPLEX_REAL32:((float*)out_buffer)[ii] = ((float*)source)[ii];break; case COMPLEX_REAL64:((float*)out_buffer)[ii] = ((double*)source)[ii];break; } ieee_big32( ((float*)out_buffer)[ii] ); } break; case ASF_BYTE: for ( ii=0; ii<num_samples_to_put; ii++ ) { switch (source_data_type) { case ASF_BYTE:((unsigned char*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case INTEGER16:((unsigned char*)out_buffer)[ii] = ((short int*)source)[ii];break; case INTEGER32:((unsigned char*)out_buffer)[ii] = ((int*)source)[ii];break; case REAL32:((unsigned char*)out_buffer)[ii] = ((float*)source)[ii];break; case REAL64:((unsigned char*)out_buffer)[ii] = ((double*)source)[ii];break; } } break; case INTEGER16: for ( ii=0; ii<num_samples_to_put; ii++ ) { switch (source_data_type) { case ASF_BYTE:((short int*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case INTEGER16:((short int*)out_buffer)[ii] = ((short int*)source)[ii];break; case INTEGER32:((short int*)out_buffer)[ii] = ((int*)source)[ii];break; case REAL32:((short int*)out_buffer)[ii] = ((float*)source)[ii];break; case REAL64:((short int*)out_buffer)[ii] = ((double*)source)[ii];break; } big16( ((short int*)out_buffer)[ii] ); } break; case INTEGER32: for ( ii=0; ii<num_samples_to_put; ii++ ) { switch (source_data_type) { case ASF_BYTE:((int*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case INTEGER16:((int*)out_buffer)[ii] = ((short int*)source)[ii];break; case INTEGER32:((int*)out_buffer)[ii] = ((int*)source)[ii];break; case REAL32:((int*)out_buffer)[ii] = ((float*)source)[ii];break; case REAL64:((int*)out_buffer)[ii] = ((double*)source)[ii];break; } big32( ((int*)out_buffer)[ii] ); } break; case REAL64: for ( ii=0; ii<num_samples_to_put; ii++ ) { switch (source_data_type) { case ASF_BYTE:((double*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case INTEGER16:((double*)out_buffer)[ii] = ((short int*)source)[ii];break; case INTEGER32:((double*)out_buffer)[ii] = ((int*)source)[ii];break; case REAL32:((double*)out_buffer)[ii] = ((float*)source)[ii];break; case REAL64:((double*)out_buffer)[ii] = ((double*)source)[ii];break; } ieee_big64( ((double*)out_buffer)[ii] ); } break; case COMPLEX_BYTE: for ( ii=0; ii<num_samples_to_put*2; ii++ ) switch (source_data_type) { case COMPLEX_BYTE:((unsigned char*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case COMPLEX_INTEGER16:((unsigned char*)out_buffer)[ii] = ((short int*)source)[ii];break; case COMPLEX_INTEGER32:((unsigned char*)out_buffer)[ii] = ((int*)source)[ii];break; case COMPLEX_REAL32:((unsigned char*)out_buffer)[ii] = ((float*)source)[ii];break; case COMPLEX_REAL64:((unsigned char*)out_buffer)[ii] = ((double*)source)[ii];break; } break; case COMPLEX_INTEGER16: for ( ii=0; ii<num_samples_to_put*2; ii++ ) { switch (source_data_type) { case COMPLEX_BYTE:((short int*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case COMPLEX_INTEGER16:((short int*)out_buffer)[ii] = ((short int*)source)[ii];break; case COMPLEX_INTEGER32:((short int*)out_buffer)[ii] = ((int*)source)[ii];break; case COMPLEX_REAL32:((short int*)out_buffer)[ii] = ((float*)source)[ii];break; case COMPLEX_REAL64:((short int*)out_buffer)[ii] = ((double*)source)[ii];break; } big16( ((short int*)out_buffer)[ii] ); } break; case COMPLEX_INTEGER32: for ( ii=0; ii<num_samples_to_put*2; ii++ ) { switch (source_data_type) { case COMPLEX_BYTE:((int*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case COMPLEX_INTEGER16:((int*)out_buffer)[ii] = ((short int*)source)[ii];break; case COMPLEX_INTEGER32:((int*)out_buffer)[ii] = ((int*)source)[ii];break; case COMPLEX_REAL32:((int*)out_buffer)[ii] = ((float*)source)[ii];break; case COMPLEX_REAL64:((int*)out_buffer)[ii] = ((double*)source)[ii];break; } big32( ((int*)out_buffer)[ii] ); } break; case COMPLEX_REAL64: for ( ii=0; ii<num_samples_to_put*2; ii++ ) { switch (source_data_type) { case COMPLEX_BYTE:((double*)out_buffer)[ii] = ((unsigned char*)source)[ii];break; case COMPLEX_INTEGER16:((double*)out_buffer)[ii] = ((short int*)source)[ii];break; case COMPLEX_INTEGER32:((double*)out_buffer)[ii] = ((int*)source)[ii];break; case COMPLEX_REAL32:((double*)out_buffer)[ii] = ((float*)source)[ii];break; case COMPLEX_REAL64:((double*)out_buffer)[ii] = ((double*)source)[ii];break; } ieee_big64( ((double*)out_buffer)[ii] ); } break; } samples_put = FWRITE(out_buffer, sample_size, num_samples_to_put, file); FREE(out_buffer); if ( samples_put != num_samples_to_put ) { printf("put_data_lines: failed to write the correct number of samples\n"); } return samples_put; }
lasErr FUNCTION c_lsclos (FILE **fd, const char *hostname, int *action) { FILE *fdtemp; int clen, dlen, total_len, empty, more, nbytes; int buf_size = 1024; char tempfile[CMLEN]; char *buffer; char dtype[TYPL]; char header[HDRL]; char *key=NULL; char msgtxt[ERRLEN + 1]; char *ptr; switch (*action) { case 0: /*** normal close ***/ FCLOSE(*fd); break; case 1: /*** crunch file ***/ FSEEK64(*fd, 0, 0); strcpy(tempfile,hostname); strcat(tempfile,"_temp"); fdtemp = FOPEN (tempfile, "w"); buffer = MALLOC((unsigned)buf_size); empty = 1; more = 1; while (more) { nbytes = fread(header,sizeof(char),HDRL,*fd); if (nbytes == 0) break; if (nbytes == -1) { c_errmsg("Error reading header record from label services file", "lsclos-read",NON_FATAL); return(E_FAIL); } clen = dlen = 0; if (((ptr = strchr(header,'/')) != NULL ) && ((int)(ptr - header) < LENL)) sscanf(header,"%d/%d%s",&clen,&dlen,dtype); else sscanf(header,"%d%s",&dlen,dtype); key = squeeze(header+LENL+TYPL,strlen(header+LENL+TYPL)); total_len = clen + dlen; if (strcmp(key,"DELETED") != 0) /* copy record */ { /* to new file */ if (total_len > buf_size) { free(buffer); buf_size = total_len; buffer = MALLOC((unsigned)buf_size); } FREAD(buffer,1,total_len,*fd); FWRITE(header,1,HDRL,fdtemp); FWRITE(buffer,1,nbytes,fdtemp); empty = 0; } else /* skip record */ { if (fseek(*fd, (int)total_len, 1) == -1) { c_errmsg("Error seeking in label services file", "lsclos-seek",NON_FATAL); return(E_FAIL); } } } free(buffer); if (fclose(*fd) != 0) { c_errmsg("Error closing label services file","lsclos-close", NON_FATAL); return(E_FAIL); } if (fclose(fdtemp) != 0) { sprintf(msgtxt,"Error closing temporary file %s",tempfile); c_errmsg(msgtxt,"lsclos-close",NON_FATAL); return(E_FAIL); } if (unlink(hostname) == -1) { sprintf(msgtxt,"Error deleting label services file %s", hostname); c_errmsg(msgtxt,"lsclos-delete",NON_FATAL); return(E_FAIL); } if (!empty) /*** delete file ***/ { if (rename(tempfile,hostname) != E_SUCC) { sprintf(msgtxt,"Error renaming file %s to %s", tempfile,hostname); c_errmsg(msgtxt,"lsclos-rename",NON_FATAL); return(E_FAIL); } } else if (unlink(tempfile) == -1) { sprintf(msgtxt,"Error deleting label services file %s", hostname); c_errmsg(msgtxt,"lsclos-delete",NON_FATAL); return(E_FAIL); } free(key); break; case 2: /*** delete file ***/ if (unlink(hostname) == -1) { sprintf(msgtxt,"Error deleting label services file %s", hostname); c_errmsg(msgtxt,"lsclos-delete",NON_FATAL); return(E_FAIL); } break; } return(E_SUCC); }
/* WIN32 MOD, CopyFile is a win32 API!*/ INT lz_CopyFile(INT doshSource, INT doshDest, PLZINFO pLZI) { DWORD ucbRead, ucbWritten; // !!! Assumes pLZI parm is valid. No sanity check (should be done above in caller). // Rewind input file again. if (FSEEK(doshSource, 0L, SEEK_SET) != 0L) { return(LZERROR_BADINHANDLE); } // Rewind output file. if (doshDest != NO_DOSH && FSEEK(doshDest, 0L, SEEK_SET) != 0L) { return( LZERROR_BADOUTHANDLE ); } // Set up a fresh buffer state. ResetBuffers(); while ((ucbRead = FREAD(doshSource, pLZI->rgbyteInBuf, pLZI->ucbInBufLen)) > 0U && #ifdef LZA_DLL ucbRead != (DWORD)(-1)) #else FERROR() == 0) #endif { if ((ucbWritten = FWRITE(doshDest, pLZI->rgbyteInBuf, ucbRead)) != ucbRead) #ifdef LZA_DLL if (ucbWritten != (DWORD)(-1)) { #else if (FERROR() != 0) { #endif return(LZERROR_BADOUTHANDLE); } else { return(LZERROR_WRITE); } pLZI->cblOutSize += ucbWritten; if (ucbRead != pLZI->ucbInBufLen) break; } #ifdef LZA_DLL // here, ucbRead == 0, EOF (proper loop termination) // == -1, bad DOS handle if (ucbRead == (DWORD)(-1)) { #else // here, FERROR() == 0U, EOF (proper loop termination) // != 0U, bad DOS handle if (FERROR() != 0U) { #endif return(LZERROR_BADINHANDLE); } // Copy successful - return number of bytes copied. return(TRUE); } /* ** int ExpandOrCopyFile(int doshDource, int doshDest); ** ** Expands one file to another. ** ** Arguments: doshSource - source DOS file handle ** doshDest - destination DOS file handle ** ** Returns: int - TRUE if expansion finished successfully. One of the ** LZERROR_ codes if not. ** ** Globals: none */ INT ExpandOrCopyFile(INT doshSource, INT doshDest, PLZINFO pLZI) { INT f; FH FHInfo; // compressed header info struct BOOL bExpandingFile; // !!! Assumes pLZI parm is valid. No sanity check (should be done above in caller). // Get compressed file header. if (GetHdr(&FHInfo, doshSource, &pLZI->cblInSize) != TRUE && pLZI->cblInSize >= (LONG)HEADER_LEN) // read error occurred return(LZERROR_BADINHANDLE); // Expand or copy input file to output file. bExpandingFile = (IsCompressed(& FHInfo) == TRUE); if (bExpandingFile) { switch (FHInfo.byteAlgorithm) { case ALG_FIRST: f = LZDecode(doshSource, doshDest, (LONG)FHInfo.cbulUncompSize - 1L, TRUE, TRUE, pLZI); break; #if 0 case ALG_LZ: f = LZDecode(doshSource, doshDest, (LONG)FHInfo.cbulUncompSize - 1L, TRUE, FALSE, pLZI); break; #endif default: f = LZERROR_UNKNOWNALG; break; } } else f = lz_CopyFile(doshSource, doshDest, pLZI); if (f != TRUE) return(f); // Flush output buffer to file. if ((f = FlushOutputBuffer(doshDest, pLZI)) != TRUE) return(f); // Copy date and time stamp from source file to destination file. if ((f = CopyDateTimeStamp(doshSource, doshDest)) != TRUE) return(f); // Did we expand the exact number of bytes we expected to from the // compressed file header entry? if (bExpandingFile && (DWORD)pLZI->cblOutSize != FHInfo.cbulUncompSize) return(LZERROR_READ); // Expansion / copying finished successfully. return(TRUE); } /* ** int Expand(char ARG_PTR *pszSource, char ARG_PTR *pszDest, BOOL bDoRename); ** ** Expands one file to another. ** ** Arguments: pszSource - name of file to compress ** pszDest - name of compressed output file ** bDoRename - flag for output file renaming ** ** Returns: int - TRUE if expansion finished successfully. One of the ** LZERROR_ codes if not. ** ** Globals: none */ INT Expand( NOTIFYPROC pfnNotify, CHAR ARG_PTR *pszSource, CHAR ARG_PTR *pszDest, BOOL bDoRename, PLZINFO pLZI) { INT doshSource, // input file handle doshDest, // output file handle f; FH FHInfo; // compressed header info struct CHAR szDestFileName[MAX_PATH]; // Sanity check if (!pLZI) { return(LZERROR_GLOBLOCK); } // Set up input file handle. Set cblInSize to length of input file. if ((f = GetIOHandle(pszSource, READ_IT, & doshSource, &pLZI->cblInSize)) != TRUE) return(f); if (GetHdr(&FHInfo, doshSource, &pLZI->cblInSize) != TRUE && pLZI->cblInSize >= (LONG)HEADER_LEN) { // Read error occurred. FCLOSE(doshSource); return(LZERROR_BADINHANDLE); } // Create destination file name. STRCPY(szDestFileName, pszDest); #if 0 if (bDoRename == TRUE && FHInfo.byteAlgorithm != ALG_FIRST) #else if (bDoRename == TRUE) #endif { // Rename output file using expanded file name extension character // stored in compressed file header. MakeExpandedName(szDestFileName, FHInfo.byteExtensionChar); } // Ask if we should compress this file. if (! (*pfnNotify)(pszSource, szDestFileName, (WORD) (IsCompressed(&FHInfo) ? NOTIFY_START_EXPAND : NOTIFY_START_COPY))) { // Don't expand / copy file. This error condition should be handled in // pfnNotify, so indicate that it is not necessary for the caller to // display an error message. FCLOSE(doshSource); return(BLANK_ERROR); } // Set up output file handle. if ((f = GetIOHandle(szDestFileName, WRITE_IT, & doshDest, &pLZI->cblInSize)) != TRUE) { FCLOSE(doshSource); return(f); } // Expand or copy input file into output file. f = ExpandOrCopyFile(doshSource, doshDest, pLZI); // Close files. FCLOSE(doshSource); FCLOSE(doshDest); return(f); }