/** * @brief * Function to assign a file descriptor and necessary information to a file * structure inorder to pursue subsequent operations * @param finfo * Pointer to a file structure where the file information is stored * @param entry * Pointer to the directory entry of the file/directory * @param mode * Mode in which the file is requested to be opened * @return * File descriptor of the file */ int retrieve_file_info(file_info *finfo,dir_entry *entry,u8 mode, u8 *dir_offset,const char *path) { file_info *temp; if(file_head == NULL) file_head = finfo; else{ temp = file_head; while(temp->next != NULL) temp = temp->next; temp->next = finfo; } finfo->fd = fdes = fdes + 1; finfo->file_path = sw_malloc(sizeof(char) * (sw_strlen(path) + 1)); sw_strcpy(finfo->file_path,path); finfo->entry = entry; finfo->strt_cluster = (entry->strt_clus_hword)<<16 | (entry->strt_clus_lword); finfo->cur_cluster = finfo->strt_cluster; finfo->cur_offset = 0; finfo->file_size = entry->size; finfo->mode = mode; finfo->bytes_traversed = 0; finfo->dir_entry_offset = dir_offset; finfo->next = NULL; return(finfo->fd); }
int echo_task_init(sa_config_t *psa_config) { sw_memset(psa_config, 0x0, sizeof(sa_config_t)); psa_config->service_uuid = OTZ_SVC_ECHO; sw_strcpy(psa_config->service_name, "echo"); psa_config->stack_size = TASK_STACK_SIZE; psa_config->data = (void*)sw_malloc(sizeof(struct echo_global)); if(!psa_config->data) { sw_printf("SW: echo task init: allocation of local storage data failed\n"); return OTZ_ENOMEM; } psa_config->entry_point = &echo_task; psa_config->process = (u32)&process_otz_echo_svc; sw_memset(psa_config->data, 0, sizeof(struct echo_global)); return OTZ_OK; }
/** * @brief function opens the file whose name is the string * pointed to by path and associates a stream with it * * @param name name of the file to be open * @param flags Mode Translated flag value for file to be open * @param ... optional third argument * * @return Returns the Index the of the FILE structure Otherwise, * NULL is returned and errno is set to indicate the error */ int _open(const char *name, int flags, ...) { #ifdef CONFIG_FILESYSTEM_SUPPORT int free_index = 0; u8 mode_val; if((free_index = get_free_index()) == 0) { errno = EMFILE; return(-1); } switch(flags) { case 0: mode_val = FILE_READ; break; case 2: mode_val = FILE_READ | FILE_WRITE; break; case 1537: mode_val = FILE_WRITE | FILE_CREATE_ALWAYS | FILE_CREATE_NEW; break; case 1538: mode_val = FILE_READ | FILE_WRITE | FILE_CREATE_ALWAYS | FILE_CREATE_NEW; break; default: errno = EINVAL; return(-1); } if((file_pointers[free_index].fd = file_open(name, mode_val)) == -1) { /*todo map the return code to an error number */ return(-1); } sw_strcpy((char*)file_names[free_index],(char*)name); errno = 0; return(free_index); #else sw_printk("file system configuration is not defined. \ Enable CONFIG_FILESYSTEM_SUPPORT.\n"); errno= EBADF; return (-1); #endif }
sw_string sw_strdup(sw_const_string str) { sw_string ret = NULL; sw_result err; if (str == NULL) { return NULL; } ret = malloc(strlen(str) + 1); sw_check(ret, exit, err = SW_E_MEM); sw_strcpy(ret, str); exit: return ret; }
/** * @brief Dispatcher task init * * This function initializes dispatcher task parameters and its get called * before the task creation * * @param psa_config: Configuration parameter for the task * * @return otz_return_t: * OTZ_OK \n * OTZ_FAIL \n */ int dispatch_task_init(sa_config_t *psa_config) { sw_memset(psa_config, 0x0, sizeof(sa_config_t)); psa_config->service_uuid = OTZ_SVC_GLOBAL; sw_strcpy(psa_config->service_name, "dispatcher"); psa_config->stack_size = TASK_STACK_SIZE; psa_config->entry_point = (u32) &dispatch_task; psa_config->data = (void *)sw_malloc_private(COMMON_HEAP_ID, sizeof(struct dispatch_global)); if(!psa_config->data) { sw_printf("SW: dispatch task init: allocation of local storage data failed\n"); return OTZ_ENOMEM; } sw_memset(psa_config->data, 0 , sizeof(struct dispatch_global)); g_dispatch_data = psa_config->data; /* INIT_LIST_HEAD( &((struct dispatch_global*)psa_config->data)->pending_list); */ return OTZ_OK; }
/** * @brief * * @param str * @param id[] */ void set_text(u8* str, u8 id[]) { countt = obj_val.obj_count-1; while(countt!=-1) { if(sw_strcmp(obj_val.obj_id[countt], id) == 0) { break; } countt--; } if(countt != -1) { s32int width = obj_val.obj_coord[countt][2] - obj_val.obj_coord[countt][0]; s32int height = obj_val.obj_coord[countt][3] - obj_val.obj_coord[countt][1]; if(sw_strcmp(obj_val.obj_type[countt], "textfield\0") == 0) { fill_rect(obj_val.obj_coord[countt][0], obj_val.obj_coord[countt][1] ,obj_val.obj_coord[countt][2], obj_val.obj_coord[countt][3], obj_val.obj_color[countt]); put_string(obj_val.obj_coord[countt][0]+10, obj_val.obj_coord[countt][1]+(height-8)/2, str, sw_strlen(str), calc_contrast_color(obj_val.obj_color[countt]), NO_TEXT_BG); sw_strcpy(obj_val.obj_str[countt], str); } if(sw_strcmp(obj_val.obj_type[countt], "password\0") == 0) { fill_rect(obj_val.obj_coord[countt][0],obj_val.obj_coord[countt][1], obj_val.obj_coord[countt][2], obj_val.obj_coord[countt][3], obj_val.obj_color[countt]); s32int i = 0; if(sw_strcmp(str, "\0") != 0) { u8 temp_str[500]; sw_strcpy(temp_str, str); while(str[i] != '\0') { str[i++] = '*'; } put_string(obj_val.obj_coord[countt][0]+10, obj_val.obj_coord[countt][1] + (height-8)/2, str, sw_strlen(str), calc_contrast_color(obj_val.obj_color[countt]), NO_TEXT_BG); sw_strcpy(obj_val.obj_str[countt], temp_str); sw_strcpy(str, temp_str); } else { put_string(obj_val.obj_coord[countt][0]+10, obj_val.obj_coord[countt][1] + (height-8)/2, str, sw_strlen(str), calc_contrast_color(obj_val.obj_color[countt]), NO_TEXT_BG); sw_strcpy(obj_val.obj_str[countt], str); } } } }