void sym_free(struct Symbol * sym) { if (sym->label != NULL) jfree(sym->label); if (sym->data != NULL) jfree(sym->data); jfree(sym); }
static dps_param_t handle_get_file_id(dps_appctx_t appctx, ptp_obj_handle_t autprint_mrk_file_id, char *dcf_file_path, ptp_obj_handle_t *id) { jint_t i; char *filename = NULL; dps_param_t rc; DECLARE_FNAME("handle_get_file_id"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); *id = 0; rc = DPS_PARAM_MAKE(DPS_RESULT_UNSUPPORTED_OP, DPS_RESULT_MIN_INVALID_VALUE); for (i=0; sample_image[i].image; i++) { if (!sample_image[i].name) continue; filename = j_strdup(sample_image[i].name); if (!filename) { DBG_E(DSLAVE_DPS_API, ("%s: error allocating memory (strdup)\n", fname)); rc = DPS_RESULT_UNEXECUTED_OP; goto Exit; } to_upper(filename); /* TODO: The code that should be implemented here is not a * straightforward string comparison. * The dcf_file_path is the image's path relative * to the DPOF file. In a real system e.g, the image'ss full path * would be reconstructed in order to do a full path search * for the file */ if (!j_strcmp(dcf_file_path+sizeof(DCF_PREFIX)-1, filename)) { jfree(filename); break; } jfree(filename); } if (sample_image[i].image) { *id = sample_image[0].id; rc = DPS_RESULT_OK; } DBG_X(DSLAVE_DPS_API, ("%s: autprint_id: 0x%X filename: %s" " img_id: 0x%X\n", fname, autprint_mrk_file_id, dcf_file_path, *id)); Exit: return rc; }
void cio_destroy(cio *io) { size_t i; cstr_destroy(io->rbuf); cstr_destroy(io->wbuf); for(i = 0; i < io->argc; i++) { obj_decr(io->argv[i]); } if(io->argv != NULL) jfree(io->argv); jfree(io); }
/** * Function name: copy_fd_desc * Description: Allocate all FD descriptors and copies them into * one structure. * Parameters: * * Return value: FD descriptor * Scope: Local **/ static fd_desc_t *copy_fd_desc(void) { pipe_desc_t *pipe = NULL; alt_interface_desc_t *alt = NULL; interface_desc_t *iface = NULL; fd_desc_t *desc = NULL; pipe = jmalloc(sizeof(pipe_desc_array), 0); if (!pipe) goto Error; j_memcpy(pipe, pipe_desc_array, sizeof(pipe_desc_array)); alt = jmalloc(sizeof(alt_desc_array), 0); if (!alt) goto Error; j_memcpy(alt, alt_desc_array, sizeof(alt_desc_array)); iface = jmalloc(sizeof(if_desc_array), 0); if (!iface) goto Error; j_memcpy(iface, if_desc_array, sizeof(if_desc_array)); desc = jmalloc(sizeof(fd_desc), 0); if (!desc) goto Error; j_memcpy(desc, &fd_desc, sizeof(fd_desc)); alt->pipes = pipe; iface->alt_ifs = alt; desc->interfaces = iface; return desc; Error: if (pipe) jfree(pipe); if (alt) jfree(alt); if (iface) jfree(iface); if (desc) jfree(desc); return NULL; }
int cevents_pop_fired(cevents *cevts, cevent_fired *fired) { cevent_fired *fevt; LOCK(&cevts->qlock); int *fd = (int*)clist_rpop(cevts->fired_fds); if(fd == NULL) { UNLOCK(&cevts->qlock); return 0; } fevt = (cevent_fired*)clist_rpop(cevts->events[*fd].fired_queue); jfree(fd); UNLOCK(&cevts->qlock); if(fevt == NULL) return 0; *fired = *fevt; jfree(fevt); return 1; }
static void execute_job(void) { static int once = 0; static jbool_t test_dpof = TEST_DPOF; dps_job_info_t *jinfo; sicd_object_t *obj; juint_t i; if (once) { once = 1; return; } if (test_dpof) { execute_dpof_job(); return; } for (i=0; sample_image[i].image; i++) ; jinfo = (dps_job_info_t*)jmalloc(i*sizeof(dps_job_info_t), M_ZERO); if (!jinfo) { DBG_E(DSLAVE_DPS_API, ("execute_job: failed to allocate job info " "array\n")); return; } for (i=0; sample_image[i].image; i++) { obj = sicd_store_find_object(app_ctx.store_id, sample_image[i].id); if (!obj) { DBG_E(DSLAVE_DPS_API, ("execute_job: could not find picture" "object (%X) in store\n", sample_image[i].id)); return; } jinfo[i].file_id = obj->id; if (TEST_DPS_CROPPING != DPS_CROPPING_OFF) { jinfo[i].cropping_area.left = TEST_DPS_CROPPING_LEFT; jinfo[i].cropping_area.top = TEST_DPS_CROPPING_TOP; jinfo[i].cropping_area.width = TEST_DPS_CROPPING_WIDTH; jinfo[i].cropping_area.height = TEST_DPS_CROPPING_HEIGHT; } j_strlcpy(jinfo[i].file_name, sample_image[i].name, DPS_FILENAME_SIZE + 1); j_strlcpy(jinfo[i].date, DATE, DPS_DATE_SIZE + 1); jinfo[i].copies = TEST_NUMBER_OF_COPIES; } dps_start_job(app_ctx.dpsh, &app_ctx.jconfig, jinfo, i); jfree(jinfo); }
int nice_copy(char *title, char *source, char *dest) { int x1=0,y1=0,x2=79,y2=25; bar(x1,y1+1,x2,y2,176,0x01); put_title(title); box(x1,(y1+y2)/2-1,x2,(y1+y2)/2+3,0x17); bar(x1+1,(y1+y2)/2,x2-1,(y1+y2)/2+2,' ',0x17); char msg[100]; sprintf(msg,"Copying %s -> %s",source,dest); put_string(x1+1,(y1+y2)/2,msg,0x17); bar(x1+1,(y1+y2)/2+2,x2-1,(y1+y2)/2+2,176,0x17); char *buffer=(char *)jmalloc(0xf000,"read buf"); if (!buffer) return 0; FILE *out=fopen(dest,"wb"); if (!out) { jfree(buffer) ; return 0; } FILE *in=fopen(source,"rb"); if (!in) { jfree(buffer); fclose(out); unlink(dest); return 0; } fseek(in,0,SEEK_END); long size=ftell(in); fseek(in,0,SEEK_SET); int osize=size; while (size) { long tr=fread(buffer,1,0xf000,in); bar(x1+1,(y1+y2)/2+2,x1+1+(x2-x1)*(osize-size-tr)/osize,(y1+y2)/2+2,178,0x17); if (fwrite(buffer,1,tr,out)!=tr) { fclose(out); fclose(in); unlink(dest); jfree(buffer); return 0; } size-=tr; } fclose(in); fclose(out); jfree(buffer); cls(); return 1; }
void cevents_destroy(cevents *cevts) { if(cevts == NULL) return; if(cevts->events != NULL) jfree(cevts->events); if(cevts->fired != NULL) jfree(cevts->fired); if(cevts->fired_queue != NULL) clist_destroy(cevts->fired_queue); LOCK_DESTROY(&cevts->lock); LOCK_DESTROY(&cevts->qlock); cevts->events = NULL; cevts->fired = NULL; cevts->fired_queue = NULL; cevents_destroy_priv_impl(cevts); jfree(cevts); }
int cevents_pop_fired(cevents *cevts, cevent_fired *fired) { cevent_fired *fevt; LOCK(&cevts->qlock); fevt = (cevent_fired*)clist_rpop(cevts->fired_queue); UNLOCK(&cevts->qlock); if(fevt == NULL) return 0; *fired = *fevt; jfree(fevt); return 1; }
void cevents_destroy(cevents *cevts) { if(cevts == NULL) return; if(cevts->events != NULL) { for(size_t i = 0; i < MAX_EVENTS; i++) { cevents_clear_fired_events(cevts, i); clist_destroy(cevts->events[i].fired_queue); } jfree(cevts->events); } if(cevts->fired_fds != NULL) clist_destroy(cevts->fired_fds); if(cevts->timers != NULL) ctimer_base_destroy(cevts->timers); LOCK_DESTROY(&cevts->lock); LOCK_DESTROY(&cevts->qlock); cevts->events = NULL; cevts->fired_fds = NULL; cevts->timers = NULL; //cevts->fired_queue = NULL; cevents_destroy_priv_impl(cevts); jfree(cevts); }
/** * Function name: uninit * Description: Un-initializes the mass storage function driver. * Parameters: * @context: (IN) FD context * * Return value: 0 on success, otherwise an error code * Scope: Local **/ static jresult_t uninit(context_t context) { fd_storage_t *fd = (fd_storage_t *)context; disable(fd); scsi_uninit(fd->scsi_device); if (fd->ep0_request) core_request_free(fd->ep0_request); if (fd->cmd_request) core_request_free(fd->cmd_request); /* Free FD Descriptor */ jfree(fd->fd_desc->interfaces->alt_ifs->pipes); jfree(fd->fd_desc->interfaces->alt_ifs); jfree(fd->fd_desc->interfaces); jfree(fd->fd_desc); jfree(fd); return 0; }
/** * Function name: mass_storage_init * Description: Initializes the mass storage function driver. * Parameters: * @ctx: (IN) Core context * * Return value: 0 on success, otherwise an error code * Scope: Global **/ jresult_t mass_storage_init(void *ctx) { jresult_t rc; fd_storage_t *fd; fd = jmalloc(sizeof(fd_storage_t), M_ZERO); if (!fd) return JENOMEM; fd->core_ctx = ctx; fd->state = STATE_DISABLED; fd->fd_desc = copy_fd_desc(); if (!fd->fd_desc) { jfree(fd); return JENOMEM; } /* Allocate requests */ fd->ep0_request = core_request_alloc(1, NULL); if (!fd->ep0_request) { DBG_E(DSLAVE_MS_USB, ("mass_storage_init: Failed to allocate ep0 " "request\n")); return JENOMEM; } fd->cmd_request = core_request_alloc(SCSI_MAX_REQUEST_SIZE, NULL); if (!fd->cmd_request) { DBG_E(DSLAVE_MS_USB, ("mass_storage_init: Failed to allocate cmd " "request\n")); return JENOMEM; } /* The completion callback of ep0 is always the same */ fd->ep0_request->complete = ep0_callback; fd->ep0_request->context = (void *)fd; rc = scsi_init(fd, &fd->total_luns, &fd->scsi_device); if (rc) return rc; return core_register_fd(fd->core_ctx, &fd_ops, (context_t)fd); }
//don't clear tabidx void cio_clear(cio *io) { size_t i; cstr_clear(io->rbuf); cstr_clear(io->wbuf); for(i = 0; i < io->argc; i++) { obj_decr(io->argv[i]); } if(io->argv != NULL) jfree(io->argv); io->mask = 0; io->reqtype = REQ_TYPE_NORMAL; io->argc = 0; io->nbulk = 0; io->bulk_len = 0; io->argv = NULL; io->flag = 0; io->wcount = 0; }
int kill_net() { if (game_face) delete game_face; game_face=new game_handler; if (join_array) jfree(join_array); join_array=NULL; if (game_sock) { delete game_sock; game_sock=NULL; } if (comm_sock) { delete comm_sock; comm_sock=NULL; } delete fman; fman=NULL; if (net_server) { delete net_server; net_server=NULL; } if (prot) { prot->cleanup(); prot=NULL; return 1; } else return 0; }
int main(int argc, char const *argv[]) { cstr s = cstr_create(1024); cstr *array; size_t len, i; cstr_ncat(s, "asasasas", 8); printf("%u %u \n", cstr_len(s), cstr_used(s)); cstr_ncat(s, "asasasas", 8); printf("%s\n", s); printf("%u %u \n", cstr_len(s), cstr_used(s)); array = cstr_split("1 2 3 4 5 ", 11, " ", 1, &len); printf("array len %lu\n", len); for(i = 0; i < len; i++) { printf("array[%lu]:%s\n", i, array[i]); cstr_destroy(array[i]); } jfree(array); cstr_destroy(s); return 0; }
void DiskWriteMda::allocate(int N1, int N2, int N3, int N4, int N5, int N6) { if (d->m_allocated) { printf("Warning: cannot allocate once array has been allocated.\n"); return; } jfclose(jfopen(d->m_path.toLatin1().data(),"wb")); //remove the file d->m_file=jfopen(d->m_path.toLatin1().data(),"wb+"); if (!d->m_file) { printf("Warning: cannot allocate. Unable to open file: %s\n",d->m_path.toLatin1().data()); return; } int dims[MDAIO_MAX_DIMS]; for (int i=0; i<MDAIO_MAX_DIMS; i++) dims[i]=1; dims[0]=N1; dims[1]=N2; dims[2]=N3; dims[3]=N4; dims[4]=N5; dims[5]=N6; int num_dims=2; for (int i=2; i<MDAIO_MAX_DIMS; i++) { if (dims[i]>1) num_dims=i+1; } d->m_total_size=1; for (int i=0; i<num_dims; i++) { d->m_total_size*=dims[i]; } d->m_mda_header.data_type=d->m_data_type; for (int i=0; i<MDAIO_MAX_DIMS; i++) d->m_mda_header.dims[i]=dims[i]; d->m_mda_header.num_dims=num_dims; mda_write_header(&d->m_mda_header,d->m_file); float *all_zeros=(float *)jmalloc(sizeof(float)*d->m_total_size); for (int j=0; j<d->m_total_size; j++) all_zeros[j]=0; mda_write_float32(all_zeros,&d->m_mda_header,d->m_total_size,d->m_file); jfree(all_zeros); d->m_allocated=true; }
~net_status_node() { jfree(name); if (show) delete show; }
static void uninit(uwd_audio_app_h app_ctx) { DBG_I(DSLAVE_AUDIO_APP, ("AUDIO_APP: uninit\n")); jfree(app_ctx); }
static int cevents_destory_priv_impl(cevents *cevts) { jfree(cevts->priv_data); return 0; }
~color_filter() { jfree(color_table); }
pmenu_item::~pmenu_item() { if (n) jfree(n); if (sub) delete sub; }
~part_sequence() { if (tframes) jfree(frames); }
static void destory_cqueue_item(cqueue_item *item) { jfree(item); }
~filename_node() { jfree(fn); delete sd; }
static void cdc_uninit_request_priv(cdc_cmd_priv_t *priv) { jfree(priv); }
static int cevents_destroy_priv_impl(cevents *cevts) { jfree(cevts->priv_data); cevts->priv_data = NULL; return 0; }
void unpackgl(char *fn, int pict_only) { unsigned short dir_length,sl,x,amread,bufsize; unsigned long offset,ret_ofs,length; char name[14],st[50],*buf; FILE *fp,*ot; CHECK(fn); fp=fopen(fn,"rb"); if (!fp) return ; if (fread(&dir_length,2,1,fp)!=1) return ; dir_length=int_to_local(dir_length)/17-1; ret_ofs=ftell(fp); while (dir_length--) { fseek(fp,ret_ofs,SEEK_SET); if (fread(&offset,4,1,fp)!=1) return ; offset=long_to_local(offset); if (fread(name,13,1,fp)!=1) return ; name[13]=0; sl=strlen(name); ret_ofs=ftell(fp); // save the current spot in the file so we can come back to it later if (toupper(name[sl-3])=='P' || toupper(name[sl-3])=='C' || !pict_only) { fseek(fp,offset,SEEK_SET); fread(&length,1,4,fp); length=long_to_local(length); if (length>1000000) exit(1); ot=fopen(name,"rb"); if (ot) { printf("File (%s) already exsist, overwrite (y/n)?\n",name); fgets(st,49,stdin); if (!(st[0]=='Y' || st[0]=='y')) length=0; fclose(ot); } if (length) ot=fopen(name,"wb"); if (!ot) return ; bufsize=0xf000; do { buf=(char *)jmalloc(bufsize,"unpack_gl::buffer"); if (!buf) bufsize-=100; } while (!buf); while (length) { if (length>bufsize) amread=bufsize; else amread=length; fread(buf,1,amread,fp); fwrite(buf,1,amread,ot); length-=amread; } jfree(buf); if (ot) fclose(ot); } } fclose(fp); }
void destory_cqueue(cqueue *cq) { while(cq->count > 0) { cqueue_pop(cq); } jfree(cq); }
~filter() { jfree(fdat); }
static void execute_dpof_job(void) { char *dpof_file = NULL; char *dpof_jobs = NULL; sicd_object_t *obj = NULL; jint_t i; dps_job_config_t jconfig; dps_job_info_t jinfo; char *filename = NULL; DECLARE_FNAME("execute_dpof_job"); DBG_X(DSLAVE_DPS_API, ("%s: entered\n", fname)); dpof_file = (char*)jmalloc(MAX_DPOF_FILE_SIZE, M_ZERO); dpof_jobs = (char*)jmalloc(MAX_DPOF_FILE_SIZE, M_ZERO); if (!dpof_file || !dpof_jobs) { DBG_E(DSLAVE_DPS_API, ("%s: failed to allocate job info\n", fname)); goto Error; } /* Generate JOB sections */ *dpof_jobs = '\0'; for (i=0; sample_image[i].image; i++) { if (!sicd_store_find_object(app_ctx.store_id, sample_image[i].id)) { DBG_E(DSLAVE_DPS_API, ("%s: could not find picture object " "(%X) in store\n", filename, sample_image[i].id)); goto Error; } filename = j_strdup(sample_image[i].name); if (!filename) { DBG_E(DSLAVE_DPS_API, ("%s: error allocating memory (strdup)." "skipping %s\n", fname, sample_image[i].name)); continue; } to_upper(filename); /* TODO: In a real system, the file name given here should be * the image's path relative to the DPOF file */ j_snprintf(dpof_jobs, MAX_DPOF_FILE_SIZE, DPOF_JOB_TEMPLATE, dpof_jobs, i+1, TEST_NUMBER_OF_COPIES, DCF_PREFIX, filename); jfree(filename); } dpof_jobs[MAX_DPOF_FILE_SIZE-1] = '\0'; /* Generate header */ j_snprintf(dpof_file, MAX_DPOF_FILE_SIZE, DPOF_HDR_TEMPLATE, dpof_jobs); dpof_file[MAX_DPOF_FILE_SIZE-1] = '\0'; DBG_X(DSLAVE_DPS_API, ("%s: DPOF file: \n%s\n\n", fname, dpof_file)); /* * DPOF file generation ends here. Proper API sample code * for DPOF printing begins here. */ /* Add DPOF virtual file to store */ obj = jmalloc(sizeof(sicd_object_t), M_ZERO); if (!obj) { DBG_E(DSLAVE_DPS_API, ("%s: failed to allocate sicd_object_t " "for sample image %u\n", fname, i+1)); goto Error; } app_ctx.dpof_file_id = obj->id = sicd_get_new_obj_handle(); obj->info.storage_id = app_ctx.store_id; obj->info.format = PTP_OBJ_FORMAT_DPOF; obj->info.compressed_size = j_strlen(dpof_file)+1; obj->info.filename = ptp_string_atow("/MISC/AUTPRINT.MRK"); obj->data = (juint8_t*)dpof_file; if (sicd_store_add_object(app_ctx.store_id, obj)) { DBG_E(DSLAVE_DPS_API, ("generate_dpof: failed on " "sicd_store_add_object (%u)\n")); goto Error; } /* Create JobInfo for DPOF file */ j_memset(&jconfig, 0, sizeof(jconfig)); jconfig.file_type = DPS_FILE_TYPE_DPOF; j_memset(&jinfo, 0, sizeof(jinfo)); jinfo.file_id = obj->id; j_strlcpy(jinfo.file_name, "/MISC/AUTPRINT.MRK", DPS_FILENAME_SIZE + 1); /* If we are testing DPOF restart, add relevant parameters */ if (TEST_DPOF_RESTART && app_ctx.can_restart) { j_memcpy(&jinfo.dpof_restart, &app_ctx.dpof_restart_info, sizeof(dpof_params_t)); } /* Send Job */ dps_start_job(app_ctx.dpsh, &jconfig, &jinfo, 1); goto Exit; Error: if (obj) sicd_free_object(NULL, obj); else if (dpof_file) jfree(dpof_file); Exit: if (dpof_jobs) jfree(dpof_jobs); }