BRL-CAD
vls.c
Go to the documentation of this file.
1 /* V L S . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 
21 #include "common.h"
22 
23 #include <stdlib.h>
24 #include <ctype.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <assert.h>
28 
29 #ifdef HAVE_STDINT_H
30 # include <stdint.h>
31 #endif
32 
33 #include "bio.h"
34 
35 #include "bu/log.h"
36 #include "bu/malloc.h"
37 #include "bu/parallel.h"
38 #include "bu/str.h"
39 #include "bu/vls.h"
40 
41 #include "./vls_internals.h"
42 
43 /* non-published globals */
44 extern const char bu_vls_message[];
45 extern const char bu_strdup_message[];
46 
47 /* private constants */
48 
49 /* minimum initial allocation size */
50 static const unsigned int _VLS_ALLOC_MIN = 32;
51 
52 /* minimum vls buffer allocation size */
53 static const unsigned int _VLS_ALLOC_READ = 4096;
54 
55 void
56 bu_vls_init(struct bu_vls *vp)
57 {
58  if (UNLIKELY(vp == (struct bu_vls *)NULL))
59  bu_bomb("bu_vls_init() passed NULL pointer");
60 
61 #if defined(DEBUG) && 0
62  /* if already a vls, sanity check for a potential memory leak. */
63  if (vp->vls_magic == BU_VLS_MAGIC) {
64  if (vp->vls_str && vp->vls_len > 0 && vp->vls_max > 0) {
65  bu_log("bu_vls_init potential leak [%s] (vls_len=%d)\n", vp->vls_str, vp->vls_len);
66  }
67  }
68 #endif
69 
70  vp->vls_magic = BU_VLS_MAGIC;
71  vp->vls_str = (char *)0;
72  vp->vls_len = vp->vls_max = vp->vls_offset = 0;
73 }
74 
75 
76 void
78 {
79  bu_log("DEPRECATION WARNING: bu_vls_init_if_uninit() should no longer be called.\n\t\tUse bu_vls_init() instead.\n");
80 
81  if (UNLIKELY(vp == (struct bu_vls *)NULL))
82  bu_bomb("bu_vls_init_if_uninit() passed NULL pointer");
83 
84  if (vp->vls_magic == BU_VLS_MAGIC)
85  return;
86  bu_vls_init(vp);
87 }
88 
89 
90 struct bu_vls *
92 {
93  struct bu_vls *vp;
94 
95  BU_ALLOC(vp, struct bu_vls);
96  bu_vls_init(vp);
97 
98  return vp;
99 }
100 
101 
102 const char *
103 bu_vls_cstr(const struct bu_vls *vp)
104 {
105  /* a wrapper for bu_vls_addr, but name is intended to be more intuitive to use */
106  return bu_vls_addr(vp);
107 }
108 
109 
110 char *
111 bu_vls_addr(const struct bu_vls *vp)
112 {
113  static char nullbuf[4] = {0, 0, 0, 0};
114  BU_CK_VLS(vp);
115 
116  if (vp->vls_max == 0 || vp->vls_str == (char *)NULL) {
117  /* A zero-length VLS is a null string */
118  nullbuf[0] = '\0'; /* sanity */
119  return nullbuf;
120  }
121 
122  /* Sanity checking */
123  if (vp->vls_str == (char *)NULL ||
124  vp->vls_len + vp->vls_offset >= vp->vls_max)
125  {
126  bu_log("bu_vls_addr: bad VLS. max=%zu, len=%zu, offset=%zu\n",
127  vp->vls_max, vp->vls_len, vp->vls_offset);
128  bu_bomb("bu_vls_addr\n");
129  }
130 
131  return vp->vls_str+vp->vls_offset;
132 }
133 
134 
135 void
136 bu_vls_extend(struct bu_vls *vp, size_t extra)
137 {
138  BU_CK_VLS(vp);
139 
140  /* allocate at least 32 bytes (8 or 4 words) extra */
141  if (extra < _VLS_ALLOC_MIN)
142  extra = _VLS_ALLOC_MIN;
143 
144  /* first time allocation.
145  *
146  * performance testing using a static buffer indicated an
147  * approximate 25% gain by avoiding this first allocation but not
148  * worth the complexity involved (e.g., extending the struct or
149  * hijacking vls_str) and it'd be error-prone whenever the vls
150  * implementation changes.
151  */
152  if (vp->vls_max <= 0 || vp->vls_str == (char *)0) {
153  vp->vls_str = (char *)bu_malloc(extra, bu_vls_message);
154  vp->vls_max = extra;
155  vp->vls_len = 0;
156  vp->vls_offset = 0;
157  *vp->vls_str = '\0';
158  return;
159  }
160 
161  /* make sure to increase in step sized increments */
162  if (extra < _VLS_ALLOC_STEP)
163  extra = _VLS_ALLOC_STEP;
164  else if (extra % _VLS_ALLOC_STEP != 0)
165  extra += _VLS_ALLOC_STEP - (extra % _VLS_ALLOC_STEP);
166 
167  /* need more space? */
168  if (vp->vls_offset + vp->vls_len + extra >= vp->vls_max) {
169  vp->vls_str = (char *)bu_realloc(vp->vls_str, (vp->vls_max + extra), bu_vls_message);
170  vp->vls_max += extra;
171  }
172 }
173 
174 
175 void
176 bu_vls_setlen(struct bu_vls *vp, size_t newlen)
177 {
178  BU_CK_VLS(vp);
179 
180  if (vp->vls_len >= newlen)
181  return;
182 
183  bu_vls_extend(vp, (unsigned)newlen - vp->vls_len);
184  vp->vls_len = newlen;
185 }
186 
187 
188 size_t
189 bu_vls_strlen(const struct bu_vls *vp)
190 {
191  BU_CK_VLS(vp);
192 
193  return vp->vls_len;
194 }
195 
196 
197 void
198 bu_vls_trunc(struct bu_vls *vp, int len)
199 {
200  BU_CK_VLS(vp);
201 
202  if (len < 0) {
203  /* now an absolute length */
204  len = vp->vls_len + len;
205  }
206  if (vp->vls_len <= (size_t)len)
207  return;
208  if (len == 0)
209  vp->vls_offset = 0;
210 
211  vp->vls_str[len+vp->vls_offset] = '\0'; /* force null termination */
212  vp->vls_len = len;
213 }
214 
215 
216 void
217 bu_vls_nibble(struct bu_vls *vp, off_t len)
218 {
219  BU_CK_VLS(vp);
220 
221  /* if the caller asks to nibble everything, truncate the string */
222  if (len > 0 && (size_t)len >= vp->vls_len) {
223  bu_vls_trunc(vp, 0);
224  return;
225  }
226 
227  /* if the caller asks to un-nibble more than we can, we just
228  * unroll to the original beginning of the string
229  */
230  if (len < 0 && (size_t)(-len) > vp->vls_offset) {
231  vp->vls_len += vp->vls_offset;
232  vp->vls_offset = 0;
233  return;
234  }
235 
236  /* could be collapsed due to prior, but appease dumb compilers */
237  if (len < 0) {
238  vp->vls_len += (size_t)(-len);
239  vp->vls_offset -= (size_t)(-len);
240  } else {
241  vp->vls_len -= (size_t)len;
242  vp->vls_offset += (size_t)len;
243  }
244 }
245 
246 
247 void
248 bu_vls_free(struct bu_vls *vp)
249 {
250  BU_CK_VLS(vp);
251 
252  if (vp->vls_str && vp->vls_max > 0) {
253  vp->vls_str[0] = '?'; /* Sanity */
254  bu_free(vp->vls_str, "bu_vls_free");
255  vp->vls_str = (char *)0;
256  }
257 
258  vp->vls_offset = vp->vls_len = vp->vls_max = 0;
259 }
260 
261 
262 void
264 {
265  if (UNLIKELY(*(unsigned long *)vp != BU_VLS_MAGIC))
266  return;
267 
268  bu_vls_free(vp);
269  bu_free(vp, "bu_vls_vlsfree");
270 }
271 
272 
273 char *
274 bu_vls_strdup(const struct bu_vls *vp)
275 {
276  char *str;
277  size_t len;
278 
279  BU_CK_VLS(vp);
280 
281  len = bu_vls_strlen(vp);
282  str = (char *)bu_malloc(len+1, bu_strdup_message);
283  bu_strlcpy(str, bu_vls_addr(vp), len+1);
284 
285  return str;
286 }
287 
288 
289 char *
291 {
292  char *str;
293 
294  BU_CK_VLS(vp);
295 
296  if (vp->vls_offset != 0 || !vp->vls_str) {
297  str = bu_vls_strdup(vp);
298  bu_vls_free(vp);
299  return str;
300  }
301 
302  str = bu_vls_addr(vp);
303  vp->vls_str = (char *)0;
304  vp->vls_offset = vp->vls_len = vp->vls_max = 0;
305  return str;
306 }
307 
308 
309 void
310 bu_vls_strcpy(struct bu_vls *vp, const char *s)
311 {
312  size_t len;
313 
314  BU_CK_VLS(vp);
315 
316  if (UNLIKELY(s == (const char *)NULL))
317  return;
318 
319  len = strlen(s);
320  if (UNLIKELY(len <= 0)) {
321  vp->vls_len = 0;
322  vp->vls_offset = 0;
323  if (vp->vls_max > 0)
324  vp->vls_str[0] = '\0';
325  return;
326  }
327 
328  /* cancel offset before extending */
329  vp->vls_offset = 0;
330  if (len+1 >= vp->vls_max)
331  bu_vls_extend(vp, len+1);
332 
333  memcpy(vp->vls_str, s, len+1); /* include null */
334  vp->vls_len = len;
335 }
336 
337 
338 void
339 bu_vls_strncpy(struct bu_vls *vp, const char *s, size_t n)
340 {
341  size_t len;
342 
343  BU_CK_VLS(vp);
344 
345  if (UNLIKELY(s == (const char *)NULL))
346  return;
347 
348  len = strlen(s);
349  if (len > n)
350  len = n;
351  if (UNLIKELY(len <= 0)) {
352  vp->vls_len = 0; /* ensure string is empty */
353  return;
354  }
355 
356  /* cancel offset before extending */
357  vp->vls_offset = 0;
358  if (len+1 >= vp->vls_max)
359  bu_vls_extend(vp, len+1);
360 
361  memcpy(vp->vls_str, s, len);
362  vp->vls_str[len] = '\0'; /* force null termination */
363  vp->vls_len = len;
364 }
365 
366 
367 void
368 bu_vls_strcat(struct bu_vls *vp, const char *s)
369 {
370  size_t len;
371 
372  BU_CK_VLS(vp);
373 
374  if (UNLIKELY(s == (const char *)NULL))
375  return;
376 
377  len = strlen(s);
378  if (UNLIKELY(len <= 0))
379  return;
380 
381  if (vp->vls_offset + vp->vls_len + len+1 >= vp->vls_max)
382  bu_vls_extend(vp, len+1);
383 
384  memcpy(vp->vls_str +vp->vls_offset + vp->vls_len, s, len+1); /* include null */
385  vp->vls_len += len;
386 }
387 
388 
389 void
390 bu_vls_strncat(struct bu_vls *vp, const char *s, size_t n)
391 {
392  size_t len;
393 
394  BU_CK_VLS(vp);
395 
396  if (UNLIKELY(s == (const char *)NULL))
397  return;
398 
399  len = strlen(s);
400  if (len > n)
401  len = n;
402  if (UNLIKELY(len <= 0))
403  return;
404 
405  if (vp->vls_offset + vp->vls_len + len+1 >= vp->vls_max)
406  bu_vls_extend(vp, len+1);
407 
408  memcpy(vp->vls_str + vp->vls_offset + vp->vls_len, s, len);
409  vp->vls_len += len;
410  vp->vls_str[vp->vls_offset + vp->vls_len] = '\0'; /* force null termination */
411 }
412 
413 
414 void
415 bu_vls_vlscat(struct bu_vls *dest, const struct bu_vls *src)
416 {
417  BU_CK_VLS(src);
418  BU_CK_VLS(dest);
419 
420  if (UNLIKELY(src->vls_len <= 0))
421  return;
422 
423  if (dest->vls_offset + dest->vls_len + src->vls_len+1 >= dest->vls_max)
424  bu_vls_extend(dest, src->vls_len+1);
425 
426  /* copy source string, including null */
427  memcpy(dest->vls_str +dest->vls_offset + dest->vls_len, src->vls_str+src->vls_offset, src->vls_len+1);
428  dest->vls_len += src->vls_len;
429 }
430 
431 
432 void
433 bu_vls_vlscatzap(struct bu_vls *dest, struct bu_vls *src)
434 {
435  BU_CK_VLS(src);
436  BU_CK_VLS(dest);
437 
438  if (UNLIKELY(src->vls_len <= 0))
439  return;
440 
441  bu_vls_vlscat(dest, src);
442  bu_vls_trunc(src, 0);
443 }
444 
445 
446 void
447 bu_vls_substr(struct bu_vls *dest, const struct bu_vls *src, size_t begin, size_t nchars)
448 {
449  size_t len;
450  size_t i, end;
451 
452  BU_CK_VLS(src);
453  BU_CK_VLS(dest);
454 
455  len = src->vls_len;
456  if (UNLIKELY(len == 0))
457  return;
458  if (UNLIKELY(begin > len))
459  return;
460  if (UNLIKELY(nchars == 0))
461  return;
462 
463  if (nchars > len)
464  nchars = len;
465 
466  bu_vls_trunc(dest, 0);
467  bu_vls_extend(dest, nchars + 1);
468 
469  end = begin + nchars;
470  if (end > len)
471  end = len;
472 
473  for (i = begin; i < end; ++i)
474  bu_vls_putc(dest, bu_vls_cstr(src)[i]);
475 
476  /* ensure we have an end */
477  bu_vls_putc(dest, '\0');
478 }
479 
480 
481 int
482 bu_vls_strcmp(struct bu_vls *s1, struct bu_vls *s2)
483 {
484  BU_CK_VLS(s1);
485  BU_CK_VLS(s2);
486 
487  /* A zero-length VLS is a null string, account for it */
488  if (s1->vls_max == 0 || s1->vls_str == (char *)NULL) {
489  /* s1 is empty */
490  /* ensure first-time allocation for null-termination */
491  bu_vls_extend(s1, 1);
492  }
493  if (s2->vls_max == 0 || s2->vls_str == (char *)NULL) {
494  /* s2 is empty */
495  /* ensure first-time allocation for null-termination */
496  bu_vls_extend(s2, 1);
497  }
498 
499  /* neither empty, straight up comparison */
500  return bu_strcmp(s1->vls_str+s1->vls_offset, s2->vls_str+s2->vls_offset);
501 }
502 
503 
504 int
505 bu_vls_strncmp(struct bu_vls *s1, struct bu_vls *s2, size_t n)
506 {
507  BU_CK_VLS(s1);
508  BU_CK_VLS(s2);
509 
510  if (UNLIKELY(n <= 0)) {
511  /* they match at zero chars */
512  return 0;
513  }
514 
515  /* A zero-length VLS is a null string, account for it */
516  if (s1->vls_max == 0 || s1->vls_str == (char *)NULL) {
517  /* s1 is empty */
518  /* ensure first-time allocation for null-termination */
519  bu_vls_extend(s1, 1);
520  }
521  if (s2->vls_max == 0 || s2->vls_str == (char *)NULL) {
522  /* s2 is empty */
523  /* ensure first-time allocation for null-termination */
524  bu_vls_extend(s2, 1);
525  }
526 
527  return bu_strncmp(s1->vls_str+s1->vls_offset, s2->vls_str+s2->vls_offset, n);
528 }
529 
530 
531 void
532 bu_vls_from_argv(struct bu_vls *vp, int argc, const char *argv[])
533 {
534  BU_CK_VLS(vp);
535 
536  for (/* nada */; argc > 0; argc--, argv++) {
537  bu_vls_strcat(vp, *argv);
538  if (argc > 1) bu_vls_strcat(vp, " ");
539  }
540 }
541 
542 
543 void
544 bu_vls_fwrite(FILE *fp, const struct bu_vls *vp)
545 {
546  size_t status;
547 
548  BU_CK_VLS(vp);
549 
550  if (UNLIKELY(vp->vls_len <= 0))
551  return;
552 
554  status = fwrite(vp->vls_str + vp->vls_offset, vp->vls_len, 1, fp);
556 
557  if (UNLIKELY(status != 1)) {
558  perror("fwrite");
559  bu_bomb("bu_vls_fwrite() write error\n");
560  }
561 }
562 
563 
564 void
565 bu_vls_write(int fd, const struct bu_vls *vp)
566 {
567  ssize_t status;
568 
569  BU_CK_VLS(vp);
570 
571  if (UNLIKELY(vp->vls_len <= 0))
572  return;
573 
575  status = write(fd, vp->vls_str + vp->vls_offset, vp->vls_len);
577 
578  if (UNLIKELY(status < 0 || (size_t)status != vp->vls_len)) {
579  perror("write");
580  bu_bomb("bu_vls_write() write error\n");
581  }
582 }
583 
584 
585 int
586 bu_vls_read(struct bu_vls *vp, int fd)
587 {
588  size_t todo;
589  int got;
590  int ret = 0;
591 
592  BU_CK_VLS(vp);
593 
594  for (;;) {
595  bu_vls_extend(vp, _VLS_ALLOC_READ);
596  todo = vp->vls_max - vp->vls_len - vp->vls_offset - 1;
597 
599  got = (int)read(fd, vp->vls_str+vp->vls_offset+vp->vls_len, todo);
601 
602  if (UNLIKELY(got < 0)) {
603  /* Read error, abandon the read */
604  return -1;
605  }
606  if (got == 0)
607  break;
608 
609  vp->vls_len += got;
610  ret += got;
611  }
612 
613  /* force null termination */
614  vp->vls_str[vp->vls_len+vp->vls_offset] = '\0';
615 
616  return ret;
617 }
618 
619 
620 int
621 bu_vls_gets(struct bu_vls *vp, FILE *fp)
622 {
623  int startlen;
624  int endlen;
625  int done;
626  char *bufp;
627  char buffer[BUFSIZ+1] = {0};
628 
629  BU_CK_VLS(vp);
630 
631  startlen = bu_vls_strlen(vp);
632 
633  do {
634  bufp = bu_fgets(buffer, BUFSIZ+1, fp);
635 
636  if (!bufp)
637  return -1;
638 
639  /* keep reading if we just filled the buffer */
640  if ((strlen(bufp) == BUFSIZ) && (bufp[BUFSIZ-1] != '\n') && (bufp[BUFSIZ-1] != '\r')) {
641  done = 0;
642  } else {
643  done = 1;
644  }
645 
646  /* strip the trailing EOL (or at least part of it) */
647  if ((bufp[strlen(bufp)-1] == '\n') || (bufp[strlen(bufp)-1] == '\r'))
648  bufp[strlen(bufp)-1] = '\0';
649 
650  /* handle \r\n lines */
651  if (bufp[strlen(bufp)-1] == '\r')
652  bufp[strlen(bufp)-1] = '\0';
653 
654  bu_vls_printf(vp, "%s", bufp);
655  } while (!done);
656 
657  /* sanity check */
658  endlen = bu_vls_strlen(vp);
659  if (endlen < startlen)
660  return -1;
661 
662  return endlen;
663 }
664 
665 void
666 bu_vls_putc(struct bu_vls *vp, int c)
667 {
668  BU_CK_VLS(vp);
669 
670  if (vp->vls_offset + vp->vls_len+1 >= vp->vls_max)
671  bu_vls_extend(vp, _VLS_ALLOC_STEP);
672 
673  vp->vls_str[vp->vls_offset + vp->vls_len++] = (char)c;
674  vp->vls_str[vp->vls_offset + vp->vls_len] = '\0'; /* force null termination */
675 }
676 
677 void
679 {
680  BU_CK_VLS(vp);
681 
682  /* Remove trailing white space */
683  while ((vp->vls_len > 0) &&
684  isspace((int)(bu_vls_addr(vp)[bu_vls_strlen(vp)-1])))
685  bu_vls_trunc(vp, -1);
686 
687  /* Remove leading white space */
688  while ((vp->vls_len > 0) &&
689  isspace((int)(*bu_vls_addr(vp))))
690  bu_vls_nibble(vp, 1);
691 }
692 
693 void
694 bu_vls_printf(struct bu_vls *vls, const char *fmt, ...)
695 {
696  va_list ap;
697  va_start(ap, fmt);
698 
699  BU_CK_VLS(vls);
700 
701  bu_vls_vprintf(vls, fmt, ap);
702  va_end(ap);
703 }
704 
705 
706 void
707 bu_vls_sprintf(struct bu_vls *vls, const char *fmt, ...)
708 {
709  va_list ap;
710  va_start(ap, fmt);
711 
712  BU_CK_VLS(vls);
713 
714  bu_vls_trunc(vls, 0); /* poof */
715  bu_vls_vprintf(vls, fmt, ap);
716  va_end(ap);
717 }
718 
719 
720 void
721 bu_vls_spaces(struct bu_vls *vp, size_t cnt)
722 {
723  BU_CK_VLS(vp);
724 
725  if (UNLIKELY(cnt == 0))
726  return;
727  if (vp->vls_offset + vp->vls_len + cnt+1 >= vp->vls_max)
728  bu_vls_extend(vp, cnt);
729 
730  memset(vp->vls_str + vp->vls_offset + vp->vls_len, ' ', cnt);
731  vp->vls_len += cnt;
732 }
733 
734 
735 size_t
737 {
738  char *start;
739  size_t used;
740 
741  BU_CK_VLS(vp);
742 
743  start = strrchr(bu_vls_addr(vp), '\n');
744  if (start == NULL)
745  start = bu_vls_addr(vp);
746 
747  used = 0;
748  while (*start != '\0') {
749  if (*start == '\t') {
750  used += 8 - (used % 8);
751  } else {
752  used++;
753  }
754  start++;
755  }
756 
757  return used;
758 }
759 
760 
761 void
762 bu_vls_detab(struct bu_vls *vp)
763 {
764  struct bu_vls src = BU_VLS_INIT_ZERO;
765  char *cp;
766  size_t used;
767 
768  BU_CK_VLS(vp);
769 
770  bu_vls_vlscatzap(&src, vp); /* make temporary copy of src */
771  bu_vls_extend(vp, bu_vls_strlen(&src) + _VLS_ALLOC_STEP);
772 
773  cp = bu_vls_addr(&src);
774  used = 0;
775  while (*cp != '\0') {
776  if (*cp == '\t') {
777  size_t todo;
778  todo = 8 - (used % 8);
779  bu_vls_spaces(vp, todo);
780  used += todo;
781  } else if (*cp == '\n') {
782  bu_vls_putc(vp, '\n');
783  used = 0;
784  } else {
785  bu_vls_putc(vp, *cp);
786  used++;
787  }
788  cp++;
789  }
790 
791  bu_vls_free(&src);
792 }
793 
794 
795 void
796 bu_vls_prepend(struct bu_vls *vp, char *str)
797 {
798  size_t len = strlen(str);
799 
800  bu_vls_extend(vp, len);
801 
802  /* memmove is supposed to be safe even if strings overlap */
803  memmove(vp->vls_str+vp->vls_offset+len, vp->vls_str+vp->vls_offset, vp->vls_len);
804 
805  /* insert the data at the head of the string */
806  memcpy(vp->vls_str+vp->vls_offset, str, len);
807 
808  vp->vls_len += len;
809 }
810 
811 /*
812  * Local Variables:
813  * mode: C
814  * tab-width: 8
815  * indent-tabs-mode: t
816  * c-file-style: "stroustrup"
817  * End:
818  * ex: shiftwidth=4 tabstop=8
819  */
ptrdiff_t ssize_t
Definition: common.h:119
void bu_vls_init(struct bu_vls *vp)
Definition: vls.c:56
const char bu_vls_message[]
Definition: globals.c:57
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
void bu_vls_strncat(struct bu_vls *vp, const char *s, size_t n)
Definition: vls.c:390
const char bu_strdup_message[]
Definition: globals.c:64
uint32_t vls_magic
Definition: vls.h:57
void bu_vls_vlsfree(struct bu_vls *vp)
Definition: vls.c:263
if lu s
Definition: nmg_mod.c:3860
void bu_vls_strcat(struct bu_vls *vp, const char *s)
Definition: vls.c:368
void bu_semaphore_acquire(unsigned int i)
Definition: semaphore.c:180
void bu_vls_trunc(struct bu_vls *vp, int len)
Definition: vls.c:198
void bu_vls_nibble(struct bu_vls *vp, off_t len)
Definition: vls.c:217
void bu_vls_strncpy(struct bu_vls *vp, const char *s, size_t n)
Definition: vls.c:339
Header file for the BRL-CAD common definitions.
size_t vls_len
Definition: vls.h:60
void * bu_malloc(size_t siz, const char *str)
Definition: malloc.c:314
void bu_vls_free(struct bu_vls *vp)
Definition: vls.c:248
int bu_strncmp(const char *string1, const char *string2, size_t n)
Definition: str.c:191
#define BU_CK_VLS(_vp)
Definition: vls.h:69
void * memset(void *s, int c, size_t n)
#define BU_ALLOC(_ptr, _type)
Definition: malloc.h:223
char * bu_vls_strgrab(struct bu_vls *vp)
Definition: vls.c:290
void bu_vls_from_argv(struct bu_vls *vp, int argc, const char *argv[])
Definition: vls.c:532
void bu_vls_sprintf(struct bu_vls *vls, const char *fmt,...)
Definition: vls.c:707
#define bu_strlcpy(dst, src, size)
Definition: str.h:60
void bu_vls_fwrite(FILE *fp, const struct bu_vls *vp)
Definition: vls.c:544
size_t bu_vls_strlen(const struct bu_vls *vp)
Definition: vls.c:189
void * bu_realloc(void *ptr, size_t siz, const char *str)
char * bu_vls_strdup(const struct bu_vls *vp)
Definition: vls.c:274
struct bu_vls * bu_vls_vlsinit(void)
Definition: vls.c:91
const char * bu_vls_cstr(const struct bu_vls *vp)
Definition: vls.c:103
char * bu_vls_addr(const struct bu_vls *vp)
Definition: vls.c:111
size_t vls_offset
Definition: vls.h:59
void bu_vls_vprintf(struct bu_vls *vls, const char *fmt, va_list ap)
Definition: vls_vprintf.c:380
void bu_semaphore_release(unsigned int i)
Definition: semaphore.c:218
void bu_vls_init_if_uninit(struct bu_vls *vp)
Definition: vls.c:77
int bu_vls_gets(struct bu_vls *vp, FILE *fp)
Definition: vls.c:621
int bu_strcmp(const char *string1, const char *string2)
Definition: str.c:171
int bu_vls_strncmp(struct bu_vls *s1, struct bu_vls *s2, size_t n)
Definition: vls.c:505
#define BU_SEM_SYSCALL
Definition: parallel.h:178
void bu_vls_printf(struct bu_vls *vls, const char *fmt,...)
Definition: vls.c:694
void bu_vls_extend(struct bu_vls *vp, size_t extra)
Definition: vls.c:136
char * vls_str
Definition: vls.h:58
int bu_vls_strcmp(struct bu_vls *s1, struct bu_vls *s2)
Definition: vls.c:482
void bu_vls_substr(struct bu_vls *dest, const struct bu_vls *src, size_t begin, size_t nchars)
Definition: vls.c:447
void bu_vls_trimspace(struct bu_vls *vp)
Definition: vls.c:678
void bu_vls_strcpy(struct bu_vls *vp, const char *s)
Definition: vls.c:310
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
int bu_vls_read(struct bu_vls *vp, int fd)
Definition: vls.c:586
char * bu_fgets(char *s, int size, FILE *stream)
Definition: fgets.c:31
void bu_vls_spaces(struct bu_vls *vp, size_t cnt)
Definition: vls.c:721
#define BU_VLS_INIT_ZERO
Definition: vls.h:84
void bu_vls_prepend(struct bu_vls *vp, char *str)
Definition: vls.c:796
#define BU_VLS_MAGIC
Definition: magic.h:65
void bu_vls_write(int fd, const struct bu_vls *vp)
Definition: vls.c:565
void bu_vls_vlscat(struct bu_vls *dest, const struct bu_vls *src)
Definition: vls.c:415
size_t vls_max
Definition: vls.h:61
void bu_vls_setlen(struct bu_vls *vp, size_t newlen)
Definition: vls.c:176
size_t bu_vls_print_positions_used(const struct bu_vls *vp)
Definition: vls.c:736
Definition: vls.h:56
void bu_bomb(const char *str) _BU_ATTR_NORETURN
Definition: bomb.c:91
void bu_vls_putc(struct bu_vls *vp, int c)
Definition: vls.c:666
void bu_vls_detab(struct bu_vls *vp)
Definition: vls.c:762
void bu_vls_vlscatzap(struct bu_vls *dest, struct bu_vls *src)
Definition: vls.c:433
#define UNLIKELY(expression)
Definition: common.h:282