int ds_set(delim_str** ds, const char* str, int len) { if (ds_resize(ds,len) != len) { ds_free(ds); return 0; } memcpy((*ds)->str, str, len); return len; }
void gm2s_test() { int size = 128; delim_str* ds1 = NULL; char* str = "I wish I were a jellyfish that cannot fall down stairs.";; char* name = "jellyfish_string"; #if 0 //delim_str testing stuff ds_print(ds1); ds_resize(&ds1,size); ds_print(ds1); memcpy(ds1->str,str,strlen(str)); ds_print(ds1); ds_free(&ds1); printf("ds1 has been free'd\n"); ds_print(ds1); #endif #if 0 //named_data testing stuff (print) named_data* nd1 = NULL; nd_print(nd1); nd_resize_name(&nd1,128); nd_print(nd1); memcpy(nd1->name,str,strlen(str)); nd_print(nd1); nd_resize_data(&nd1,128); nd_print(nd1); memcpy(nd1->data,name,strlen(name)); nd_print(nd1); nd_free(&nd1); printf("nd1 is free'd\n"); nd_print(nd1); #endif #if 0 //test named data list stuff int count = 1024; named_data* nda[count]; named_data* list = NULL; for (int i=0; i<count; i++) { nda[i] = NULL; nd_resize_data(&nda[i],strlen(str)+1); memcpy(nda[i]->data,str,strlen(str)); nd_resize_name(&nda[i],strlen(name)+1); memcpy(nda[i]->name,name,strlen(name)); nda[i]->order = (int)(((double)rand()/RAND_MAX)*100.0); nd_add_sorted(&list,&nda[i]); //nd_print_all(list); } nd_print_all(list); nd_free_all(&list); #endif #if 0 //test subtitle stuff (printing, list op) int count = 110; subtitle* sa[count]; subtitle* list = NULL; for (int i=0; i<count; i++) { sa[i] = NULL; sub_resize(&sa[i],128); memcpy(sa[i]->txt->str,str,strlen(str)); sa[i]->txt_color = 0x11223344; sa[i]->bord_color = 0x66778899; sa[i]->start_frame = (int)(((double)rand()/RAND_MAX)*100.0); sa[i]->end_frame = 123; sa[i]->x = 40; sa[i]->y = 80; sub_add_sorted(&list,&sa[i]); sub_print_all(list); } sub_free_all(&list); #endif }
static void pax_copy_out_one_file (int top_level, int handle, dynamic_string *input_name, struct stat *stat_info) { int tar_flag = 0; if (top_level) current_device = stat_info->st_dev; /* If we aren't allowed to cross devices, and this file does, then skip it. */ if (!cross_device_flag && stat_info->st_dev != current_device) return; /* FIXME: other versions of pax always dump directories first, even for cpio formats. We could do this if we were smarter. For instance when we see a directory, we could push its name and mode on a list, and only chmod it when we're done reading. There are caveats to this plan: 1) Deal with HPUX CDF somehow. (The code might need fixing). 2) If the user types C-c, we might want to catch it and set the modes correctly (though we aren't required to). */ if (archive_format == V7_FORMAT || archive_format == POSIX_FORMAT || archive_format == GNUTAR_FORMAT) { /* In tar, we dump directories first. */ tar_flag = 1; verbosely_copy_out_file (handle, input_name, stat_info); } if (S_ISDIR (stat_info->st_mode)) { /* Recursively do directory. */ DIR *dirp; dirp = opendir (input_name->string); if (!dirp) error (0, errno, _("cannot open directory %s"), input_name->string); else { int len; dynamic_string new_name; struct dirent *d; len = ds_strlen (input_name); /* Big enough for directory, plus most files. FIXME wish I could remember the actual statistic about typical filename lengths. I recall reading that whoever developed the fast file system did such a study. */ ds_init (&new_name, len + 32); strcpy (new_name.string, input_name->string); if (input_name->string[ds_strlen (input_name) - 1] != '/') { strcat (new_name.string, "/"); len++; } /* Remove "./" from front of all file names. */ if ((len == 2 && new_name.string[0] == '.' && new_name.string[1] == '/') || (len == 1 && new_name.string[0] == '.')) len = 0; while ((d = readdir (dirp))) { if (is_dot_or_dotdot (d->d_name)) continue; ds_resize (&new_name, NAMLEN (d) + len + 1); strncpy (new_name.string + len, d->d_name, NAMLEN (d)); new_name.string[len + NAMLEN (d)] = '\0'; dump_one_file (0, handle, &new_name); } closedir (dirp); ds_destroy (&new_name); } } if (!tar_flag) /* In cpio formats, we dump directories last. */ verbosely_copy_out_file (handle, input_name, stat_info); }