libisoburn  1.5.4
About: libisoburn is a frontend for the libraries libburn and libisofs which enables creation and expansion of ISO-9660 filesystems on all media and file types supported by libburn. It implements the API and command interpreter of program xorriso, and installs this program as small dynamically linked binary. xorriso is suitable for incremental data backup and for production of bootable ISO 9660 images. A statically linked version is available as GNU xorriso.
  Fossies Dox: libisoburn-1.5.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

sort_cmp.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define Xorriso_pvt_sort_cmp_includeD   yes
 

Functions

int Xorriso__findi_sorted_ino_cmp (const void *p1, const void *p2)
 
int Xorriso__hln_cmp (const void *p1, const void *p2)
 
int Xorriso__findi_sorted_cmp (const void *p1, const void *p2)
 
int Xorriso__search_node (void *node_array[], int n, int(*cmp)(const void *p1, const void *p2), void *node, int *idx, int flag)
 
int Xorriso_search_in_hln_array (struct XorrisO *xorriso, void *node, int *idx, int flag)
 
int Xorriso__get_di (IsoNode *node, dev_t *dev, ino_t *ino, int flag)
 
int Xorriso__di_ino_cmp (const void *p1, const void *p2)
 
int Xorriso__di_cmp (const void *p1, const void *p2)
 
int Xorriso__sort_di (void *node_array[], int count, int flag)
 
int Xorriso_invalidate_di_item (struct XorrisO *xorriso, IsoNode *node, int flag)
 
int Xorriso_search_di_range (struct XorrisO *xorriso, IsoNode *node, int *idx, int *low, int *high, int flag)
 
int Xorriso__node_lba_cmp (const void *node1, const void *node2)
 
int Xorriso__node_name_cmp (const void *node1, const void *node2)
 
int Xorriso_sorted_node_array (struct XorrisO *xorriso, IsoDir *dir_node, int *nodec, IsoNode ***node_array, off_t boss_mem, int flag)
 
int Xorriso_remake_hln_array (struct XorrisO *xorriso, int flag)
 
int Xorriso_make_di_array (struct XorrisO *xorriso, int flag)
 
int Xorriso_search_hardlinks (struct XorrisO *xorriso, IsoNode *node, int *node_idx, int *min_hl, int *max_hl, int flag)
 

Macro Definition Documentation

◆ Xorriso_pvt_sort_cmp_includeD

#define Xorriso_pvt_sort_cmp_includeD   yes

Definition at line 14 of file sort_cmp.h.

Function Documentation

◆ Xorriso__di_cmp()

int Xorriso__di_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 225 of file sort_cmp.c.

226 {
227  int ret;
228  IsoNode *n1, *n2;
229 
230  ret= Xorriso__di_ino_cmp(p1, p2);
231  if(ret)
232  return(ret);
233  n1= *((IsoNode **) p1);
234  n2= *((IsoNode **) p2);
235  if(n1 != n2)
236  return(n1 < n2 ? -1 : 1);
237  return(0);
238 }
int Xorriso__di_ino_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:194

References Xorriso__di_ino_cmp().

Referenced by Xorriso__sort_di(), Xorriso_hardlink_update(), Xorriso_invalidate_di_item(), and Xorriso_search_di_range().

◆ Xorriso__di_ino_cmp()

int Xorriso__di_ino_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 194 of file sort_cmp.c.

195 {
196  int ret;
197  IsoNode *n1, *n2;
198  dev_t d1, d2;
199  ino_t i1, i2;
200 
201  n1= *((IsoNode **) p1);
202  n2= *((IsoNode **) p2);
203 
204  ret= Xorriso__get_di(n1, &d1, &i1, 0);
205  if(ret <= 0)
206  {d1= 0; i1= 0;}
207  ret= Xorriso__get_di(n2, &d2, &i2, 0);
208  if(ret <= 0)
209  {d2= 0; i2= 0;}
210 
211  if(d1 < d2)
212  return(-1);
213  if(d1 > d2)
214  return(1);
215  if(i1 < i2)
216  return(-1);
217  if(i1 > i2)
218  return(1);
219  if(d1 == 0 && i1 == 0 && n1 != n2)
220  return(n1 < n2 ? -1 : 1);
221  return(0);
222 }
int Xorriso__get_di(IsoNode *node, dev_t *dev, ino_t *ino, int flag)
Definition: sort_cmp.c:145

References Xorriso__get_di().

Referenced by Xorriso__di_cmp(), and Xorriso_search_di_range().

◆ Xorriso__findi_sorted_cmp()

int Xorriso__findi_sorted_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 69 of file sort_cmp.c.

70 {
71  int ret;
72 
73  ret= Xorriso__findi_sorted_ino_cmp(p1, p2);
74  if(ret)
75  return (ret > 0 ? 1 : -1);
76  if(p1 != p2)
77  return(p1 < p2 ? -1 : 1);
78  return(0);
79 }
int Xorriso__findi_sorted_ino_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:34

References Xorriso__findi_sorted_ino_cmp().

Referenced by Xorriso_sort_node_array().

◆ Xorriso__findi_sorted_ino_cmp()

int Xorriso__findi_sorted_ino_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 34 of file sort_cmp.c.

35 {
36  int ret;
37  IsoNode *n1, *n2;
38 
39  n1= *((IsoNode **) p1);
40  n2= *((IsoNode **) p2);
41 
42  ret= Xorriso__node_lba_cmp(&n1, &n2);
43  if(ret)
44  return (ret > 0 ? 1 : -1);
45  ret= iso_node_cmp_ino(n1, n2, 0);
46  return(ret);
47 }
int Xorriso__node_lba_cmp(const void *node1, const void *node2)
Definition: sort_cmp.c:308

References Xorriso__node_lba_cmp().

Referenced by Xorriso__findi_sorted_cmp(), Xorriso__hln_cmp(), Xorriso_restore_node_array(), Xorriso_search_hardlinks(), and Xorriso_search_in_hln_array().

◆ Xorriso__get_di()

int Xorriso__get_di ( IsoNode *  node,
dev_t *  dev,
ino_t *  ino,
int  flag 
)

Definition at line 145 of file sort_cmp.c.

146 {
147  int ret, i, i_end, imgid, error_code;
148  size_t value_length= 0;
149  char *value= NULL, *msg= NULL, severity[80];
150  unsigned char *vpt;
151  static char *name= "isofs.di";
152 
153 #ifdef NIX
154  /* <<< */
155  Xorriso_get_di_counteR++;
156 #endif /* NIX */
157 
158  msg= TSOB_FELD(char, ISO_MSGS_MESSAGE_LEN);
159  if(msg == NULL)
160  {ret= -1; goto ex;}
161  *dev= 0;
162  *ino= 0;
163  ret= iso_node_lookup_attr(node, name, &value_length, &value, 0);
164  if(ret <= 0) {
165  /* Drop any pending messages because there is no xorriso to take them */
166  iso_obtain_msgs("NEVER", &error_code, &imgid, msg, severity);
167  goto ex;
168  }
169  vpt= (unsigned char *) value;
170  if(vpt[0] > sizeof(ino_t)) {
171 
172  /* >>> obviously not the same system that recorded the device number */;
173 
174  }
175  for(i= 1; i <= vpt[0] && i < (int) value_length; i++)
176  *dev= ((*dev) << 8) | vpt[i];
177  i_end= i + vpt[i] + 1;
178  if(vpt[i] > sizeof(ino_t)) {
179 
180  /* >>> obviously not the same system that recorded the inode number */;
181 
182  }
183  for(i++; i < i_end && i < (int) value_length; i++)
184  *ino= ((*ino) << 8) | vpt[i];
185  free(value);
186  ret= 1;
187 ex:;
188  if(msg != NULL)
189  free(msg);
190  return(ret);
191 }
#define TSOB_FELD(typ, count)
Definition: sfile.h:15

References TSOB_FELD.

Referenced by Xorriso__di_ino_cmp(), and Xorriso_hardlink_update().

◆ Xorriso__hln_cmp()

int Xorriso__hln_cmp ( const void *  p1,
const void *  p2 
)

Definition at line 53 of file sort_cmp.c.

54 {
55  int ret;
56 
57  ret= Xorriso__findi_sorted_ino_cmp(&p1, &p2);
58  if(ret)
59  return (ret > 0 ? 1 : -1);
60  if(p1 != p2)
61  return(p1 < p2 ? -1 : 1);
62  return(0);
63 }

References Xorriso__findi_sorted_ino_cmp().

Referenced by Xorriso_remake_hln_array().

◆ Xorriso__node_lba_cmp()

int Xorriso__node_lba_cmp ( const void *  node1,
const void *  node2 
)

Definition at line 308 of file sort_cmp.c.

309 {
310  int ret;
311  int lba1= 0, lba2= 0;
312 
313  ret= Xorriso__file_start_lba(*((IsoNode **) node1), &lba1, 0);
314  if(ret!=1)
315  lba1= 0;
316  ret= Xorriso__file_start_lba(*((IsoNode **) node2), &lba2, 0);
317  if(ret!=1)
318  lba2= 0;
319  return(lba1-lba2);
320 }
int Xorriso__file_start_lba(IsoNode *node, int *lba, int flag)
Definition: iso_tree.c:2259

References Xorriso__file_start_lba().

Referenced by Xorriso__findi_sorted_ino_cmp(), and Xorriso_findi_iter().

◆ Xorriso__node_name_cmp()

int Xorriso__node_name_cmp ( const void *  node1,
const void *  node2 
)

Definition at line 323 of file sort_cmp.c.

324 {
325  char *name1, *name2;
326 
327  name1= (char *) iso_node_get_name(*((IsoNode **) node1));
328  name2= (char *) iso_node_get_name(*((IsoNode **) node2));
329  return(strcmp(name1,name2));
330 }

Referenced by Xorriso_sorted_node_array().

◆ Xorriso__search_node()

int Xorriso__search_node ( void *  node_array[],
int  n,
int(*)(const void *p1, const void *p2)  cmp,
void *  node,
int *  idx,
int  flag 
)

Definition at line 92 of file sort_cmp.c.

95 {
96  int ret, l, r, p, pos;
97 
98  if(n == 0)
99  return(0);
100  l= 0;
101  r= n + 1;
102  while(1) {
103  p= (r - l) / 2;
104  if(p == 0)
105  break;
106  p+= l;
107 
108  /* NULL elements may indicate invalid nodes.Their first valid right neighbor
109  will serve as proxy. If none exists, then the test pushes leftwards.
110  */
111  for(pos= p - 1; pos < n; pos++)
112  if(node_array[pos] != NULL)
113  break;
114  if(pos < n)
115  ret= (*cmp)(&(node_array[pos]), &node);
116  else
117  ret= 1;
118 
119  if(ret < 0)
120  l= p;
121  else if(ret > 0)
122  r= p;
123  else {
124  *idx= pos;
125  return(1);
126  }
127  }
128  return(0);
129 }

Referenced by Xorriso_hardlink_update(), Xorriso_invalidate_di_item(), Xorriso_search_di_range(), and Xorriso_search_in_hln_array().

◆ Xorriso__sort_di()

int Xorriso__sort_di ( void *  node_array[],
int  count,
int  flag 
)

Definition at line 241 of file sort_cmp.c.

242 {
243  if(count <= 0)
244  return(0);
245  qsort(node_array, count, sizeof(IsoNode *), Xorriso__di_cmp);
246  return(1);
247 }
int Xorriso__di_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:225

References Xorriso__di_cmp().

Referenced by Xorriso_make_di_array().

◆ Xorriso_invalidate_di_item()

int Xorriso_invalidate_di_item ( struct XorrisO xorriso,
IsoNode *  node,
int  flag 
)

Definition at line 250 of file sort_cmp.c.

252 {
253  int ret, idx;
254 
255  if(xorriso->di_array == NULL)
256  return(1);
257  ret= Xorriso__search_node(xorriso->di_array, xorriso->di_count,
258  Xorriso__di_cmp, node, &idx, 0);
259  if(ret <= 0)
260  return(ret == 0);
261  if(xorriso->di_array[idx] != NULL)
262  iso_node_unref(xorriso->di_array[idx]);
263  xorriso->di_array[idx]= NULL;
264  return(1);
265 }
int Xorriso__search_node(void *node_array[], int n, int(*cmp)(const void *p1, const void *p2), void *node, int *idx, int flag)
Definition: sort_cmp.c:92
void ** di_array

References XorrisO::di_array, XorrisO::di_count, Xorriso__di_cmp(), and Xorriso__search_node().

Referenced by Xorriso_rmi().

◆ Xorriso_make_di_array()

int Xorriso_make_di_array ( struct XorrisO xorriso,
int  flag 
)

Definition at line 518 of file sort_cmp.c.

519 {
520  int ret, bytes;
521 
522 #ifdef NIX
523  /* <<< */
524  unsigned long old_gdic;
525  old_gdic= Xorriso_get_di_counteR;
526 #endif /* NIX */
527 
528  if((xorriso->ino_behavior & 8 ) && !(flag & 2))
529  return(2);
530  if(xorriso->di_array != NULL && !(flag & 1))
531  return(2);
532  Xorriso_finish_hl_update(xorriso, 0);
533 
534  ret= Xorriso_all_node_array(xorriso, 0, 0);
535  if(ret <= 0)
536  goto ex;
537  bytes= xorriso->node_array_size / 8 + 1;
538  xorriso->di_do_widen= calloc(bytes, 1);
539  if(xorriso->di_do_widen == NULL) {
540  Xorriso_no_malloc_memory(xorriso, NULL, 0);
541  ret= -1; goto ex;
542  }
543 
544  /* Transfer node_array to di_array without unrefering nodes */
545  xorriso->di_count= xorriso->node_counter;
546  xorriso->di_array= xorriso->node_array;
547  xorriso->node_counter= 0;
548  xorriso->node_array_size= 0;
549  xorriso->node_array= NULL;
550 
551  Xorriso__sort_di((void *) xorriso->di_array, xorriso->di_count, 0);
552 
553  ret= 1;
554 ex:;
555 
556 #ifdef NIX
557 /* <<< */
558  fprintf(stderr, "xorriso_DEBUG: sort_count= %lu\n",
559  Xorriso_get_di_counteR - old_gdic);
560 #endif /* NIX */
561 
562  return(ret);
563 }
int Xorriso_all_node_array(struct XorrisO *xorriso, int addon_nodes, int flag)
Definition: iso_manip.c:3709
int Xorriso_finish_hl_update(struct XorrisO *xorriso, int flag)
Definition: sort_cmp.c:704
int Xorriso__sort_di(void *node_array[], int count, int flag)
Definition: sort_cmp.c:241
char * di_do_widen
int ino_behavior
void ** node_array
int node_counter
int node_array_size
int Xorriso_no_malloc_memory(struct XorrisO *xorriso, char **to_free, int flag)
Definition: text_io.c:4077

◆ Xorriso_remake_hln_array()

int Xorriso_remake_hln_array ( struct XorrisO xorriso,
int  flag 
)

Definition at line 388 of file sort_cmp.c.

389 {
390  int ret, addon_nodes= 0, i, old_count, old_pt, new_pt;
391  IsoNode **old_nodes;
392  char **old_targets;
393 
394  /* Count hln_targets of which the node has been deleted meanwhile */
395  for(i= 0; i < xorriso->hln_count; i++) {
396  if(xorriso->hln_targets[i] == NULL)
397  continue;
398  if(Xorriso_node_is_valid(xorriso, xorriso->hln_array[i], 0))
399  continue;
400  addon_nodes++;
401  }
402  ret= Xorriso_all_node_array(xorriso, addon_nodes, 0);
403  if(ret <= 0)
404  goto ex;
405  if(addon_nodes > 0) {
406  /* Transfer delete nodes with hln_target to node array */
407  for(i= 0; i < xorriso->hln_count; i++) {
408  if(xorriso->hln_targets[i] == NULL)
409  continue;
410  if(Xorriso_node_is_valid(xorriso, xorriso->hln_array[i], 0))
411  continue;
412  if(xorriso->node_counter < xorriso->node_array_size) {
413  xorriso->node_array[xorriso->node_counter++]= xorriso->hln_array[i];
414  iso_node_ref(xorriso->node_array[xorriso->node_counter - 1]);
415  }
416  }
417  }
418 
419  Xorriso_sort_node_array(xorriso, 0);
420  old_nodes= (IsoNode **) xorriso->hln_array;
421  old_targets= (char **) xorriso->hln_targets;
422  old_count= xorriso->hln_count;
423  xorriso->hln_array= 0;
424  xorriso->hln_targets= NULL;
425 
426  /* Transfer node_array to di_array without unrefering nodes */
427  xorriso->hln_count= xorriso->node_counter;
428  xorriso->hln_array= xorriso->node_array;
429  xorriso->node_counter= 0;
430  xorriso->node_array_size= 0;
431  xorriso->node_array= NULL;
432 
433  /* Allocate hln_targets */
434  ret= Xorriso_new_hln_array(xorriso, xorriso->temp_mem_limit, 1);
435  if(ret<=0)
436  goto ex;
437  xorriso->node_targets_availmem= xorriso->temp_mem_limit;
438  if(old_targets != NULL) {
439  /* Transfer targets from old target array */;
440  new_pt= old_pt= 0;
441  while(new_pt < xorriso->hln_count && old_pt < old_count) {
442  ret= Xorriso__hln_cmp(xorriso->hln_array[new_pt], old_nodes[old_pt]);
443  if(ret < 0) {
444  new_pt++;
445  } else if(ret > 0) {
446  old_pt++;
447  } else {
448  xorriso->hln_targets[new_pt]= old_targets[old_pt];
449  if(old_targets[old_pt] != NULL)
450  xorriso->temp_mem_limit-= strlen(old_targets[old_pt]) + 1;
451  old_targets[old_pt]= NULL;
452  new_pt++;
453  old_pt++;
454  }
455  }
456  for(old_pt= 0; old_pt < old_count; old_pt++)
457  if(old_targets[old_pt] != NULL) /* (should not happen) */
458  free(old_targets[old_pt]);
459  free((char *) old_targets);
460  }
461  if(old_nodes != NULL) {
462  for(old_pt= 0; old_pt < old_count; old_pt++)
463  if(old_nodes[old_pt] != NULL)
464  iso_node_unref(old_nodes[old_pt]);
465  free((char *) old_nodes);
466  }
467  xorriso->hln_change_pending= 0;
468  ret= 1;
469 ex:;
470  return(ret);
471 }
int Xorriso_new_hln_array(struct XorrisO *xorriso, off_t mem_limit, int flag)
Definition: base_obj.c:752
int Xorriso_node_is_valid(struct XorrisO *xorriso, IsoNode *in_node, int flag)
Definition: iso_tree.c:384
int Xorriso_sort_node_array(struct XorrisO *xorriso, int flag)
Definition: sort_cmp.c:82
int Xorriso__hln_cmp(const void *p1, const void *p2)
Definition: sort_cmp.c:53
void ** hln_array
void ** hln_targets
off_t node_targets_availmem
int hln_change_pending
int temp_mem_limit

References XorrisO::hln_array, XorrisO::hln_change_pending, XorrisO::hln_count, XorrisO::hln_targets, XorrisO::node_array, XorrisO::node_array_size, XorrisO::node_counter, XorrisO::node_targets_availmem, XorrisO::temp_mem_limit, Xorriso__hln_cmp(), Xorriso_all_node_array(), Xorriso_new_hln_array(), Xorriso_node_is_valid(), and Xorriso_sort_node_array().

Referenced by Xorriso_make_hln_array().

◆ Xorriso_search_di_range()

int Xorriso_search_di_range ( struct XorrisO xorriso,
IsoNode *  node,
int *  idx,
int *  low,
int *  high,
int  flag 
)

Definition at line 272 of file sort_cmp.c.

274 {
275  int ret, i, found;
276  int (*cmp)(const void *p1, const void *p2)= Xorriso__di_ino_cmp;
277 
278  if(flag & 2)
279  cmp= Xorriso__di_cmp;
280 
281  *high= *low= *idx= -1;
282  ret= Xorriso__search_node(xorriso->di_array, xorriso->di_count,
283  cmp, node, &found, 0);
284  if(ret <= 0)
285  return(0);
286  *low= *high= found;
287  for(i= found + 1; i < xorriso->di_count; i++)
288  if(xorriso->di_array[i] != NULL) {
289  if((*cmp)(&node, &(xorriso->di_array[i])) != 0)
290  break;
291  *high= i;
292  }
293  for(i= found - 1; i >= 0; i--)
294  if(xorriso->di_array[i] != NULL) {
295  if((*cmp)(&node, &(xorriso->di_array[i])) != 0)
296  break;
297  *low= i;
298  }
299  for(i= *low; i <= *high; i++)
300  if(xorriso->di_array[i] == node) {
301  *idx= i;
302  break;
303  }
304  return(*idx >= 0 || (flag & 1));
305 }

References XorrisO::di_array, XorrisO::di_count, Xorriso__di_cmp(), Xorriso__di_ino_cmp(), and Xorriso__search_node().

Referenced by Xorriso_hardlink_update(), and Xorriso_widen_hardlink().

◆ Xorriso_search_hardlinks()

int Xorriso_search_hardlinks ( struct XorrisO xorriso,
IsoNode *  node,
int *  node_idx,
int *  min_hl,
int *  max_hl,
int  flag 
)

Definition at line 2601 of file iso_tree.c.

2603 {
2604  int idx, ret, i, node_count;
2605  void *np, **node_array;
2606 
2607  node_array= xorriso->hln_array;
2608  node_count= xorriso->hln_count;
2609  *min_hl= *max_hl= -1;
2610  np= node;
2611  if(flag & 2) {
2612  idx= *node_idx;
2613  if(flag & 4) {
2614  node_array= xorriso->node_array;
2615  node_count= xorriso->node_counter;
2616  }
2617  } else {
2618  *node_idx= -1;
2619  ret= Xorriso_search_in_hln_array(xorriso, np, &idx, 0);
2620  if(ret <= 0)
2621  return(ret);
2622  }
2623  for(i= idx - 1; i >= 0 ; i--)
2624  if(Xorriso__findi_sorted_ino_cmp(&(node_array[i]), &np) != 0)
2625  break;
2626  *min_hl= i + 1;
2627  for(i= idx + 1; i < node_count; i++)
2628  if(Xorriso__findi_sorted_ino_cmp(&(node_array[i]), &np) != 0)
2629  break;
2630  *max_hl= i - 1;
2631 
2632  /* Search for *node_idx */
2633  if(flag & 2)
2634  return(1);
2635  for(i= *min_hl; i <= *max_hl; i++)
2636  if(node_array[i] == np) {
2637  if((flag & 1) && xorriso->hln_targets != NULL && !(flag & 4))
2638  if(xorriso->hln_targets[i] != NULL)
2639  continue;
2640  *node_idx= i;
2641  break;
2642  }
2643  return(1);
2644 }
int Xorriso_search_in_hln_array(struct XorrisO *xorriso, void *node, int *idx, int flag)
Definition: sort_cmp.c:132

References XorrisO::hln_array, XorrisO::hln_count, XorrisO::hln_targets, XorrisO::node_array, XorrisO::node_counter, Xorriso__findi_sorted_ino_cmp(), and Xorriso_search_in_hln_array().

Referenced by Xorriso_fake_stbuf(), Xorriso_restore_prefix_hl(), and Xorriso_restore_target_hl().

◆ Xorriso_search_in_hln_array()

int Xorriso_search_in_hln_array ( struct XorrisO xorriso,
void *  node,
int *  idx,
int  flag 
)

Definition at line 132 of file sort_cmp.c.

134 {
135  int ret;
136 
137  if(xorriso->hln_array == NULL || xorriso->hln_count <= 0)
138  return(0);
139  ret= Xorriso__search_node(xorriso->hln_array, xorriso->hln_count,
140  Xorriso__findi_sorted_ino_cmp, node, idx, 0);
141  return ret;
142 }

References XorrisO::hln_array, XorrisO::hln_count, Xorriso__findi_sorted_ino_cmp(), and Xorriso__search_node().

Referenced by Xorriso_search_hardlinks().

◆ Xorriso_sorted_node_array()

int Xorriso_sorted_node_array ( struct XorrisO xorriso,
IsoDir *  dir_node,
int *  nodec,
IsoNode ***  node_array,
off_t  boss_mem,
int  flag 
)

Definition at line 337 of file sort_cmp.c.

341 {
342  int i, ret, failed_at;
343  char *npt;
344  IsoDirIter *iter= NULL;
345  IsoNode *node;
346  off_t mem;
347 
348  mem= ((*nodec)+1)*sizeof(IsoNode *);
349  ret= Xorriso_check_temp_mem_limit(xorriso, mem+boss_mem, flag&2);
350  if(ret<=0)
351  return(ret);
352 
353  *node_array= calloc(sizeof(IsoNode *), (*nodec)+1);
354  if(*node_array==NULL) {
355  sprintf(xorriso->info_text,
356  "Cannot allocate memory for %d directory entries", *nodec);
357  Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
358  return(-1);
359  }
360 
361  ret= iso_dir_get_children(dir_node, &iter);
362  if(ret<0) {
363  Xorriso_cannot_create_iter(xorriso, ret, 0);
364  return(-1);
365  }
366 
367  for(i= 0; iso_dir_iter_next(iter, &node) == 1 && i<*nodec; ) {
368  npt= (char *) iso_node_get_name(node);
369  if(!(flag&4)) {
370  ret= Xorriso_regexec(xorriso, npt, &failed_at, 0);
371  if(ret)
372  continue; /* no match */
373  }
374  if(flag&1)
375  if(!LIBISO_ISDIR(node))
376  continue;
377  (*node_array)[i++]= node;
378  }
379  iso_dir_iter_free(iter);
380  *nodec= i;
381  if(*nodec<=0)
382  return(1);
383  qsort(*node_array, *nodec, sizeof(IsoNode *), Xorriso__node_name_cmp);
384  return(1);
385 }
int Xorriso_cannot_create_iter(struct XorrisO *xorriso, int iso_error, int flag)
Definition: iso_manip.c:2509
#define LIBISO_ISDIR(node)
Definition: iso_tree.h:17
int Xorriso_regexec(struct XorrisO *xorriso, char *to_match, int *failed_at, int flag)
Definition: match.c:225
int Xorriso_check_temp_mem_limit(struct XorrisO *xorriso, off_t mem, int flag)
Definition: parse_exec.c:2896
int Xorriso__node_name_cmp(const void *node1, const void *node2)
Definition: sort_cmp.c:323
char info_text[10 *4096]
int Xorriso_msgs_submit(struct XorrisO *xorriso, int error_code, char msg_text[], int os_errno, char severity[], int flag)
Submit a problem message to the xorriso problem reporting and handling system.
Definition: text_io.c:2504

References XorrisO::info_text, LIBISO_ISDIR, Xorriso__node_name_cmp(), Xorriso_cannot_create_iter(), Xorriso_check_temp_mem_limit(), Xorriso_msgs_submit(), and Xorriso_regexec().

Referenced by Xorriso_ls(), and Xorriso_show_du_subs().