int create_response_stream(struct connect_context * cc, struct http_context * hc, const char * path) { FILE * file = NULL; long file_len = 0; if (*path == '/' && *(path + 1) != 0) file = fopen(path + 1, "rb"); if (file == NULL) { printf("not found: %s\n", path); sprintf(cc->response, resp404_template, strlen(resp404_body)); strncat(cc->response, resp404_body, sizeof(cc->response)); cc->resplen = strlen(cc->response); return 0; } cc->respfile = file; fseek(file, 0, SEEK_END); file_len = ftell(file); rewind(file); sprintf(cc->response, resp200_template, file_len, get_file_type(path)); cc->resplen = strlen(cc->response); cc->flags |= CF_URLFILE; cc->respoff = 0; //printf("request: %s\n", path); return 0; }
void serve_static(int fd, char *filename, int filesize) { int srcfd; char filetype[MAXLINE], buf[MAXLINE], *body; /* 发送 Response headers 到客户端 */ get_file_type(filename, filetype); sprintf(buf, "HTTP/1.0 200 OK \r\n"); rio_writen(fd, buf, strlen(buf)); sprintf(buf, "Server: toyws\r\n"); rio_writen(fd, buf, strlen(buf)); sprintf(buf, "Content-type: %s\r\n", filetype); rio_writen(fd, buf, strlen(buf)); sprintf(buf, "Content-length: %d\r\n\r\n", filesize); rio_writen(fd, buf, strlen(buf)); /* 发送Response body */ srcfd = open(filename, 'r'); body = (char *)malloc(filesize); memset(body, filesize, 0); /* 读取文件内容到body */ while (rio_readline(srcfd, buf, MAXLINE)) { sprintf(body, "%s%s",body, buf); } close(srcfd); rio_writen(fd, body, filesize); free(body); }
void build_ustar_header_from_file(FILE_HEADER* header, char* filename) { struct stat buffer; errno = 0; if(stat(filename, &buffer) == 0 && errno == 0) { clean_up_header(header); get_prefix_and_name(filename, header->name, header->prefix); get_file_mode(header->mode, buffer.st_mode); get_id(header->uid, buffer.st_uid); get_id(header->gid, buffer.st_gid); get_size(header->size, buffer.st_size); get_modification_time(header->mtime, buffer.st_mtime); get_file_type(header->typeflag, buffer.st_mode); strcpy(header->magic, "ustar "); strcpy(header->version, " \0"); get_username(header->uname, buffer.st_uid); get_groupname(header->gname, buffer.st_gid); get_device_numbers(header->devmajor, header->devminor, buffer.st_dev); calculate_checksum(header); } else fprintf(stderr, "%s '%s': %s\n", STAT_FAILURE_ERR, filename, strerror(errno)); }
void do_head(int fd, char *uri) { struct stat sbuf; char filename[MAXLINE], cgiargs[MAXLINE]; //read_request_headers(fd); /* 读取并忽略headers */ /* 从HEAD request 中解析 URI */ parse_uri(uri, filename, cgiargs); printf("request filename: %s\n",filename); if (stat(filename, &sbuf) < 0) { send_error(fd, filename, "404", "Not Found"); return; } if (!(S_ISREG(sbuf.st_mode)) || !(S_IRUSR & sbuf.st_mode)) { send_error(fd, filename, "403", "Forbidden"); return; } int filesize = sbuf.st_size; char filetype[MAXLINE], buf[MAXLINE], *body; /* 发送 Response headers 到客户端 */ get_file_type(filename, filetype); sprintf(buf, "HTTP/1.0 200 OK \r\n"); rio_writen(fd, buf, strlen(buf)); sprintf(buf, "Server: toyws\r\n"); rio_writen(fd, buf, strlen(buf)); sprintf(buf, "Content-type: %s\r\n", filetype); rio_writen(fd, buf, strlen(buf)); sprintf(buf, "Content-length: %d\r\n\r\n", filesize); rio_writen(fd, buf, strlen(buf)); close(fd); return; }
FT_EXPORT_DEF( FT_Error ) FT_New_Face( FT_Library library, const char* pathname, FT_Long face_index, FT_Face *aface ) { FT_Open_Args args; FSSpec spec; OSType file_type; /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !pathname ) return FT_Err_Invalid_Argument; if ( file_spec_from_path( pathname, &spec ) ) return FT_Err_Invalid_Argument; file_type = get_file_type( &spec ); if ( file_type == 'FFIL' || file_type == 'tfil' ) return FT_New_Face_From_Suitcase( library, &spec, face_index, aface ); else if ( file_type == 'LWFN' ) return FT_New_Face_From_LWFN( library, &spec, face_index, aface ); else { args.flags = ft_open_pathname; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); } }
void get_requested_file_info(const char * recv_buffer,uufile_t *fileinfo) { char visit_file_name_local[VISIT_FILE_NAME]={0,}; char visit_file_argv[VISIT_FILE_ARGV]={0,}; get_visit_file_name_and_argv(recv_buffer,visit_file_name_local,visit_file_argv,VISIT_FILE_ARGV); if( 0 != strlen(visit_file_argv)){ strncpy(fileinfo->argv,visit_file_argv,ARGV_STRING_MAX); } strncpy(fileinfo->name,"www/",VISIT_FILE_NAME); if( 0 == strlen(visit_file_name_local)){ strncat(fileinfo->name,"index.html",VISIT_FILE_NAME); } else{ strncat(fileinfo->name,visit_file_name_local,VISIT_FILE_NAME); } if( FILE_NOT_EXIST == is_exist(fileinfo->name)){ strncpy(fileinfo->name,"www/notfound.html",VISIT_FILE_NAME); } printf("all file name is: %s\n",fileinfo->name); fileinfo->type = get_file_type(fileinfo->name); fileinfo->size = get_file_size(fileinfo->name); }
void set_primary_subtitle_file(int id) { int fid; if(id == -1) id = sel_sub_default; if(id == -1) return; if(!sub_files) return; if(id >= sub_file_count) return; if(subs_pri) sub_list_uninitialize(subs_pri); if(!id < 0) { subs_pri = 0; sel_sub_pri = 0; return; } subs_pri = sub_list_initialize(); fid = get_file_type(sub_files[id].path); read_text_subtitle_file(sub_files[id].path, fid, subs_pri); sel_sub_pri = id; }
int get_song_length(char *filename) { int ret = -1; int file_type = 0; if (filename) { file_type = get_file_type(filename); switch(file_type) { case FILE_TYPE_WAV: ret = wav_get_song_length(filename); break; case FILE_TYPE_OGG: ret = ogg_get_song_length(filename); break; case FILE_TYPE_MP3: ret = mpg_get_song_length(filename); break; default: break; } } return ret; }
int is_supported_file_type(settings_t *settings, char *filename) { int ret = 0; int type = 0; if (settings) { type = get_file_type(filename); switch(type) { case FILE_TYPE_MP3: ret = ((settings->mpgdec_enabled) ? 1 : 0); break; case FILE_TYPE_OGG: ret = ((settings->oggdec_enabled) ? 1 : 0); break; case FILE_TYPE_WAV: ret = 1; break; case FILE_TYPE_M3U: ret = 1; break; case FILE_TYPE_PLS: /* NOT YET */ ret = 0; break; } } return ret; }
int infos_header(t_header *head, char *arg) { struct stat *stats; if ((stats = malloc(sizeof(struct stat))) == NULL || stat(arg, stats) == -1 || sprintf(head->size, "%0*lo", 11, (long)stats->st_size) < 0 || sprintf(head->mode, "%0*lo", 7, (long)stats->st_mode) < 0 || sprintf(head->mtime, "%0*lo", 11, (long)stats->st_mtime) < 0 || (head->type_flag[0] = get_file_type(stats)) < 0 || check_name(head, arg) == 1 || strncpy(head->magic, "ustar ", 8) == NULL || strncpy(head->version, " \0", 2) == NULL || sprintf(head->uid, "%0*o", 7, stats->st_uid) < 0 || sprintf(head->gid, "%0*o", 7, stats->st_gid) < 0 || strncpy(head->uname, (getpwuid(stats->st_uid))->pw_name, 32) == NULL || strncpy(head->gname, (getgrgid(stats->st_gid))->gr_name, 32) == NULL) return (1); if ((head->type_flag[0] == '3' || head->type_flag[0] == '4') && ((sprintf(head->devmajor, "%d", major(stats->st_rdev)) < 0 || sprintf(head->devminor, "%d", minor(stats->st_rdev)) < 0))) return (1); else if (head->type_flag[0] == '2' && readlink(head->type_flag, head->linkname, 100) < 0) return (1); free(stats); return (0); }
/* check if there is a static lib associated to a given dll */ static char *find_static_lib( const char *dll ) { char *lib = strmake("%s.a", dll); if (get_file_type(lib) == file_arh) return lib; free( lib ); return NULL; }
int add_posix(t_file *file, char *buffer) { unsigned char p; int blk; int perms; p = 0; blk = 0; buffer[p++] = get_file_type(file); while (blk < 3) { perms = (int)file->stats.st_mode >> (2 - blk) * 3; buffer[p] = (perms & S_IROTH) ? 'r' : '-'; buffer[p + 1] = (perms & S_IWOTH) ? 'w' : '-'; if ((blk == 2) && (perms & S_ISVTX)) buffer[p + 2] = (perms & S_IXOTH) ? 't' : 'T'; else buffer[p + 2] = (perms & S_IXOTH) ? 'x' : '-'; p += 3; blk++; } buffer[p++] = ' '; fix_suid(buffer, (int)file->stats.st_mode); buffer[p] = '\0'; return (p); }
static boolean filter_type(const int current_param, const char* const* params, StatType* file_info) { const char* parameter1 = NULL; parameter1 = params[current_param + 1]; /* check if option argument describes the same file type as file to examine has */ return (*parameter1 == get_file_type(file_info)); }
static void instrument_file(const char * source_file, const char * destination_file, const char * id, int instrumenting) { if (g_verbose) { printf("Instrumenting file %s\n", id); } /* check if they are the same */ char * canonical_source_file = make_canonical_path(source_file); char * canonical_destination_file = make_canonical_path(destination_file); check_same_file(canonical_source_file, canonical_destination_file); free(canonical_source_file); free(canonical_destination_file); if (instrumenting) { enum FileType file_type = get_file_type(source_file); switch (file_type) { case FILE_TYPE_OTHER: case FILE_TYPE_HTML: copy_file(source_file, destination_file); break; case FILE_TYPE_JS: { FILE * input = xfopen(source_file, "rb"); FILE * output = xfopen(destination_file, "wb"); Stream * input_stream = Stream_new(0); Stream * output_stream = Stream_new(0); Stream_write_file_contents(input_stream, input); size_t num_characters = input_stream->length; uint16_t * characters = NULL; int result = jscoverage_bytes_to_characters(jscoverage_encoding, input_stream->data, input_stream->length, &characters, &num_characters); if (result == JSCOVERAGE_ERROR_ENCODING_NOT_SUPPORTED) { fatal("encoding %s not supported", jscoverage_encoding); } else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) { fatal("error decoding %s in file %s", jscoverage_encoding, id); } jscoverage_instrument_js(id, characters, num_characters, output_stream); free(characters); if (fwrite(output_stream->data, 1, output_stream->length, output) != output_stream->length) { fatal("cannot write to file: %s", destination_file); } Stream_delete(input_stream); Stream_delete(output_stream); fclose(input); fclose(output); } break; } } else { copy_file(source_file, destination_file); } }
/** * @brief Checks whether a file or directory exists * @param filename null-terminated string, with a filename to check * @return 1 if the given file or directory exists; 0 otherwise * @see http://stackoverflow.com/a/12774387/2042871 * @see get_file_type * @author Cristian Martinez */ int file_exists(const char* filename) { // This is different than the af_fopen() approach implemented in // fexists(). Under POSIX systems, get_file_type() uses stat() to // check if the file exists, in Windows, it uses GetFileAttributes(). // Hence, this function could return 1 (file exists) even if the file // isn't readable. Besides that, this is reported to be faster than // open and then close the file return (get_file_type(filename) > FILE_NOT_FOUND); }
static int concat_and_get_file_type(const char *dir, const char *filename) { char buf[MAX_PATH]; /* Make fullpath */ int err = concat_path(buf, dir, filename); if (err) { return err; } /* Stat */ return get_file_type(buf); }
/** * 解析目录的结构 * 构造目录树 */ static int parse_dir(const char *dirpath) { DIR *dp; struct dirent *dirp; int cnt = 0; if ((dp = opendir(dirpath)) == NULL) { log_err("Open dir error : %s", dirpath); exit(1); } struct stat buf; char fullpath[200]; while((dirp = readdir(dp)) != NULL) { //忽略隐藏目录和文件 if (dirp -> d_name[0] == '.') { continue; } //拼接子文件的完整路径。 strcpy(fullpath, dirpath); //适当的加上/ if (fullpath[strlen(fullpath) - 1] != '/') { strcat(fullpath, "/"); } strcat(fullpath, dirp -> d_name); //获得文件的状态,并判断其是否是目录 if (stat(fullpath, &buf) < 0) { log_err("Get file state error : %s", fullpath); } if (S_ISDIR(buf.st_mode)) //是目录,递归的处理之。 { cnt += parse_dir(fullpath); continue; } if (get_file_type(dirp -> d_name) == UNKNOWN_F_T) { continue; } path_tree_add(pt, fullpath); //log_info("Insert path : %s", fullpath); ++cnt; } closedir(dp); return cnt; }
int xml_print_dir(const char* dir) { DIR *dirp; struct dirent *d; struct stat stats; int num_files = 0; if((dirp = opendir(dir)) == NULL) return(-1); chdir(dir); while((d = readdir(dirp)) != NULL) { xmlChar *xml_str; char atime[20]; char mtime[20]; int size_len; if ((d->d_name == NULL) || !strcmp(d->d_name, ".") || !strcmp(d->d_name, "..")) continue; if(lstat(d->d_name, &stats) != 0) { fprintf(stderr, "couldn't stat: %s\n", d->d_name); } #if defined (__MINGW32__) /* somehow atime is -1 on Windows XP when the atime is in future */ if (stats.st_atime < 0) stats.st_atime = 0; /* somehow mtime is -1 on Windows XP when the mtime is in future */ if (stats.st_mtime < 0) stats.st_mtime = 0; #endif /* format time as per ISO 8601 */ strftime(atime, sizeof atime, "%Y%m%dT%H%M%SZ", gmtime(&stats.st_atime)); strftime(mtime, sizeof mtime, "%Y%m%dT%H%M%SZ", gmtime(&stats.st_mtime)); xml_str = xml_C11NNormalizeAttr((const xmlChar *) d->d_name); printf("<%s p=\"%s\" a=\"%s\" m=\"%s\" s=\"", get_file_type(stats.st_mode), get_file_perms(stats.st_mode), atime, mtime); size_len = printf("%lu", (unsigned long) stats.st_size); printf("\"%.*s", 16-size_len, " "); printf(" n=\"%s\"/>\n", xml_str); num_files++; xmlFree(xml_str); } /* end of for loop */ closedir(dirp); return num_files; }
gboolean is_playable_file(const gchar *file) { if (!file) return FALSE; if (g_file_test(file, G_FILE_TEST_IS_REGULAR) && (get_file_type((gchar*)file) != -1)) return TRUE; else return FALSE; }
static void directory_walk(struct minix_superblock *sb, unsigned long address) { unsigned long offset = 0; struct minix_dentry dentry; struct minix_inode inode; unsigned long inode_tbl_bass = get_inode_table_address(*sb); int i; while (1) { // read first entry. read_dentry(&dentry, address, offset); if (dentry.inode == 0) break; read_inode(dentry.inode, &inode, inode_tbl_bass); printf("inode:0x%x name %s\n", dentry.inode, dentry.name); printf("i_mode: 0x%x(0x%x)\n", inode.i_mode, get_file_type(&inode)); printf("i_nlinks: 0x%x\n", inode.i_nlinks); printf("uid: 0x%x\n", inode.i_uid); printf("gid: 0x%x\n", inode.i_gid); printf("i_size: 0x%x\n", inode.i_size); printf("i_atime: 0x%x\n", inode.i_atime); printf("i_mtime: 0x%x\n", inode.i_mtime); printf("i_ctime: 0x%x\n", inode.i_ctime); for (i = 0; i < NR_I_ZONE; i++) { if (inode.i_zone[i]) printf("zone[%d]: 0x%x(0x%x)\n", i, inode.i_zone[i], get_data_zone(inode.i_zone[i])); } if ((get_file_type(&inode) == I_FT_DIR) && (strcmp(dentry.name, ".")) && (strcmp(dentry.name, ".."))) directory_walk(sb, get_data_zone(inode.i_zone[0])); offset += sizeof(dentry) - 1; } }
/*! Scans a service directory in dpi_dir and fills dpi_attr * \Note * Caller must allocate memory for dpi_attr. * \Return * \li 0 on success * \li -1 on failure * \todo * Add other file types, but first we need to add files associated with a dpi * to the design. */ int get_dpi_attr(char *dpi_dir, char *service, struct dp *dpi_attr) { char *service_dir = NULL; struct stat statinfo; enum file_type ftype; int ret = -1; DIR *dir_stream; struct dirent *dir_entry = NULL; service_dir = dStrconcat(dpi_dir, "/", service, NULL); if (stat(service_dir, &statinfo) == -1) { ERRMSG("get_dpi_attr", "stat", errno); MSG_ERR("file=%s\n", service_dir); } else if ((dir_stream = opendir(service_dir)) == NULL) { ERRMSG("get_dpi_attr", "opendir", errno); } else { /* Scan the directory looking for dpi files. * (currently there's only the dpi program, but in the future * there may also be helper scripts.) */ while ( (dir_entry = readdir(dir_stream)) != NULL) { if (dir_entry->d_name[0] == '.') continue; ftype = get_file_type(dir_entry->d_name); switch (ftype) { case DPI_FILE: dpi_attr->path = dStrconcat(service_dir, "/", dir_entry->d_name, NULL); dpi_attr->id = dStrdup(service); dpi_attr->port = 0; dpi_attr->pid = 1; if (strstr(dpi_attr->path, ".filter") != NULL) dpi_attr->filter = 1; else dpi_attr->filter = 0; ret = 0; break; default: break; } } closedir(dir_stream); if (ret != 0) MSG_ERR("get_dpi_attr: No dpi plug-in in %s/%s\n", dpi_dir, service); } dFree(service_dir); return ret; }
static u_int16_t find_file(struct minix_superblock *sb, unsigned long address, const char *fname) { unsigned long offset = 0; struct minix_dentry dentry; struct minix_inode inode; unsigned long inode_tbl_bass = get_inode_table_address(*sb); const char *tmp; u_int16_t ret = 0; int len = 0; int ftype; while (1) { // read first entry. read_dentry(&dentry, address, offset); if (dentry.inode == 0) break; read_inode(dentry.inode, &inode, inode_tbl_bass); tmp = fname; if (tmp[0] == '/') tmp = tmp + 1; ftype = get_file_type(&inode); if (ftype == I_FT_DIR) { len = count_delimita_length(tmp, '/'); if (len == -1) { if (!strcmp(tmp, dentry.name)) return dentry.inode; } else if (!strncmp(tmp, dentry.name, len)) { ret = find_file(sb, get_data_zone(inode.i_zone[0]), tmp + len); } else { // if final character is '/', finish searching. if (!strcmp(tmp + len, "/")) return dentry.inode; } } else if (ftype == I_FT_REGULAR) { if (!strcmp(dentry.name, tmp)) return dentry.inode; } if (ret) return ret; offset += sizeof(dentry) - 1; } return 0; }
static char* try_lib_path(const char* dir, const char* pre, const char* library, const char* ext, file_type expected_type) { char *fullname; file_type type; /* first try a subdir named from the library we are looking for */ fullname = strmake("%s/%s/%s%s%s", dir, library, pre, library, ext); if (verbose > 1) fprintf(stderr, "Try %s...", fullname); type = get_file_type(fullname); if (verbose > 1) fprintf(stderr, type == expected_type ? "FOUND!\n" : "no\n"); if (type == expected_type) return fullname; free( fullname ); fullname = strmake("%s/%s%s%s", dir, pre, library, ext); if (verbose > 1) fprintf(stderr, "Try %s...", fullname); type = get_file_type(fullname); if (verbose > 1) fprintf(stderr, type == expected_type ? "FOUND!\n" : "no\n"); if (type == expected_type) return fullname; free( fullname ); return 0; }
static int dir_mount(mount_t *mnt, const char *path) { /* Check the path is actually a directory */ if ( get_file_type(path) != FILESYSTEM_TDIR ) { return FILESYSTEM_EFAILURE; } /* Init mount */ mnt->udata = NULL; mnt->unmount = dir_unmount; mnt->exists = dir_exists; mnt->isFile = dir_isFile; mnt->isDirectory = dir_isDirectory; mnt->read = dir_read; /* Return ok */ return FILESYSTEM_ESUCCESS; }
void set_custom_primary_subtitle_file(const string fpath) { int fid; if(subs_pri) sub_list_uninitialize(subs_pri); if(!fpath) { subs_pri = 0; sel_sub_pri = -1; return; } subs_pri = sub_list_initialize(); fid = get_file_type(fpath); read_text_subtitle_file(fpath, fid, subs_pri); sel_sub_pri = -2; /* custom */ }
int send_response_header(int conn_fd, char *file_name, int file_size) { /* * Transmit the HTTP response header on the client's connection socket. */ char file_type[MAXLINE], buf[MAXBUF]; int len; get_file_type(file_name, file_type); sprintf(buf, "HTTP/1.0 200 OK\r\n"); sprintf(buf, "%sContent-length: %d\r\n", buf, file_size); sprintf(buf, "%sContent-type: %s\r\n\r\n", buf, file_type); len = strlen(buf); if (rio_writen(conn_fd, buf, len) != len) { dbg_printf("rio_writen returned an error\n"); return ERROR; } return SUCCESS; }
bool ModelIO::load(const string& path, TriangleMesh * p_triangle_mesh) { std::ifstream in(path.c_str()); if (!in.good()) { error("file not exists: %s", path.c_str()); return false; } Assert(p_triangle_mesh != nullptr); string ext = get_file_type(path); if (ext == "obj") return load_obj(path, in, p_triangle_mesh); else error("Unsupported model file type: %s\n", ext.c_str()); return false; }
static void update_alerts_from_theme_name (GvcSoundThemeChooser *chooser, const gchar *name) { if (strcmp (name, CUSTOM_THEME_NAME) != 0) { /* reset alert to default */ update_alert (chooser, DEFAULT_ALERT_ID); } else { int sound_type; char *linkname; linkname = NULL; sound_type = get_file_type ("bell-terminal", &linkname); g_debug ("Found link: %s", linkname); if (sound_type == SOUND_TYPE_CUSTOM) { update_alert (chooser, linkname); } } }
FT_New_Face( FT_Library library, const char* pathname, FT_Long face_index, FT_Face *aface ) { FT_Open_Args args; FSSpec spec; OSType file_type; /* test for valid `library' and `aface' delayed to FT_Open_Face() */ if ( !pathname ) return FT_Err_Invalid_Argument; if ( file_spec_from_path( pathname, &spec ) ) return FT_Err_Invalid_Argument; /* Regardless of type, don't try to use the resource fork if it is */ /* empty. Some TTF fonts have type `FFIL', for example, but they */ /* only have data forks. */ if ( ResourceForkSize( &spec ) != 0 ) { file_type = get_file_type( &spec ); if ( file_type == 'FFIL' || file_type == 'tfil' ) return FT_New_Face_From_Suitcase( library, &spec, face_index, aface ); if ( file_type == 'LWFN' ) return FT_New_Face_From_LWFN( library, &spec, face_index, aface ); } #if TARGET_API_MAC_CARBON if ( is_dfont( &spec ) ) return FT_New_Face_From_dfont( library, &spec, face_index, aface ); #endif /* let it fall through to normal loader (.ttf, .otf, etc.) */ args.flags = ft_open_pathname; args.pathname = (char*)pathname; return FT_Open_Face( library, &args, face_index, aface ); }
sptensor_t * mpi_simple_distribute( char const * const ifname, MPI_Comm comm) { int rank, npes; MPI_Comm_rank(comm, &rank); MPI_Comm_size(comm, &npes); sptensor_t * tt = NULL; FILE * fin = NULL; if(rank == 0) { fin = open_f(ifname, "r"); } switch(get_file_type(ifname)) { case SPLATT_FILE_TEXT_COORD: tt = p_tt_mpi_read_file(fin, comm); break; case SPLATT_FILE_BIN_COORD: tt = p_tt_mpi_read_binary_file(fin, comm); break; } if(rank == 0) { fclose(fin); } /* set dims info */ #pragma omp parallel for schedule(static, 1) for(idx_t m=0; m < tt->nmodes; ++m) { idx_t const * const inds = tt->ind[m]; idx_t dim = 1 +inds[0]; for(idx_t n=1; n < tt->nnz; ++n) { dim = SS_MAX(dim, 1 + inds[n]); } tt->dims[m] = dim; } return tt; }