FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
util.c
Go to the documentation of this file.
1 /***************************************************************
2  Copyright (C) 2006-2009 Hewlett-Packard Development Company, L.P.
3 
4  This program is free software; you can redistribute it and/or
5  modify it under the terms of the GNU General Public License
6  version 2 as published by the Free Software Foundation.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License along
14  with this program; if not, write to the Free Software Foundation, Inc.,
15  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 
17  ***************************************************************/
18 /* Equivalent to core nomos v1.29 */
19 
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include "nomos.h"
29 #include "util.h"
30 #include "list.h"
31 #include "nomos_regex.h"
32 #include "nomos_utils.h"
33 
34 #define MM_CACHESIZE 20
35 #define MAXLENGTH 100
36 
37 #ifdef REUSE_STATIC_MEMORY
38 static char grepzone[10485760]; /* 10M for now, adjust if needed */
39 #endif /* REUSE_STATIC_MEMORY */
40 
41 /*
42  File local variables
43  */
44 static va_list ap;
45 static char utilbuf[myBUFSIZ];
46 static struct mm_cache mmap_data[MM_CACHESIZE];
47 static char cmdBuf[512];
48 
49 
50 #ifdef MEMORY_TRACING
51 #define MEMCACHESIZ 200000
52 static int memlast = -1;
53 static struct mm_cache memcache[MEMCACHESIZ];
54 void memCacheDump();
55 #endif /* MEMORY_TRACING */
56 
62 int isDIR(char *dpath)
63 {
64 #ifdef PROC_TRACE
65  traceFunc("== isDIR(%s)\n", dpath);
66 #endif /* PROC_TRACE */
67 
68  return(isINODE(dpath, S_IFDIR));
69 }
70 
77 int isEMPTYFILE(char *fpath)
78 {
79 #ifdef PROC_TRACE
80  traceFunc("== isEMPTYFILE(%s)\n", fpath);
81 #endif /* PROC_TRACE */
82 
83  if (!isFILE(fpath)) {
84  return(0);
85  }
86  return(cur.stbuf.st_size == 0);
87 }
88 
95 int isBLOCK(char *bpath)
96 {
97 #ifdef PROC_TRACE
98  traceFunc("== isBLOCK(%s)\n", bpath);
99 #endif /* PROC_TRACE */
100 
101  return(isINODE(bpath, S_IFBLK));
102 }
103 
110 int isCHAR(char *cpath)
111 {
112 #ifdef PROC_TRACE
113  traceFunc("== isCHAR(%s)\n", cpath);
114 #endif /* PROC_TRACE */
115 
116  return(isINODE(cpath, S_IFCHR));
117 }
118 
125 int isPIPE(char *ppath)
126 {
127 #ifdef PROC_TRACE
128  traceFunc("== isPIPE(%s)\n", ppath);
129 #endif /* PROC_TRACE */
130 
131  return(isINODE(ppath, S_IFIFO));
132 }
133 
140 int isSYMLINK(char *spath)
141 {
142 #ifdef PROC_TRACE
143  traceFunc("== isSYMLINK(%s)\n", spath);
144 #endif /* PROC_TRACE */
145 
146  return(isINODE(spath, S_IFLNK));
147 }
148 
155 int isINODE(char *ipath, int typ)
156 {
157  int ret;
158  char sErrorBuf[1024];
159 
160 #ifdef PROC_TRACE
161  traceFunc("== isINODE(%s, 0x%x)\n", ipath, typ);
162 #endif /* PROC_TRACE */
163 
164  if ((ret = stat(ipath, &cur.stbuf)) < 0) {
165  /*
166  IF we're trying to stat() a file that doesn't exist,
167  that's no biggie.
168  Any other error, however, is fatal.
169  */
170  if (errno == ENOENT) {
171  return 0;
172  }
173  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
174  LOG_ERROR("Error: %s getting stat on file: %s", sErrorBuf, ipath)
175  }
176  if (typ == 0) {
177  return(1);
178  }
179  return((int)(cur.stbuf.st_mode & S_IFMT & typ));
180 }
181 
187 char *newReloTarget(char *basename)
188 {
189  static char newpath[myBUFSIZ];
190  int i;
191 
192 #ifdef PROC_TRACE
193  traceFunc("== newReloTarget(%s)\n", basename);
194 #endif /* PROC_TRACE */
195 
196  for (i = 0; i < MAX_RENAME; i++) {
197  (void) sprintf(newpath, "%s_%s-renamed.%03d", basename, gl.progName, i);
198  if (access(newpath, F_OK) && errno == ENOENT) {
199  break;
200  }
201  }
202  if (i == MAX_RENAME) {
203  LOG_FATAL("%s: no suitable relocation target (%d tries)", basename, i)
204  Bail(-__LINE__);
205  }
206  return(newpath);
207 }
208 
209 
210 
211 #ifdef MEMORY_TRACING
212 
217 char *memAllocTagged(int size, char *name)
218 {
219  void *ptr;
220  sErrorBuf[1024];
221 
222  /*
223  * we don't track memory allocated; we front-end for errors and return
224  * the pointer we were given.
225  */
226 
227 #if defined(PROC_TRACE) || defined(MEM_ACCT)
228  traceFunc("== memAllocTagged(%d, \"%s\")\n", size, name);
229 #endif /* PROC_TRACE || MEM_ACCT */
230 
231  if (size < 1) {
232  LOG_FATAL("Cannot alloc %d bytes!", size)
233  Bail(-__LINE__);
234  }
235  if (++memlast == MEMCACHESIZ) {
236  LOG_FATAL("*** memAllocTagged: out of memcache entries")
237  Bail(-__LINE__);
238  }
239 #ifdef USE_CALLOC
240  if ((ptr = calloc((size_t) 1, (size_t) size)) == (void *) NULL) {
241  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
242  LOG_FATAL("calloc for %s, error: %s", name, sErrorBuf)
243  Bail(-__LINE__);
244  }
245 #else /* not USE_CALLOC */
246  if ((ptr = malloc((size_t) size)) == (void *) NULL) {
247  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
248  LOG_FATAL("malloc for %s, error: %s", name, sErrorBuf)
249  Bail(-__LINE__);
250  }
251  (void) memset(ptr, 0, (size_t) size);
252 #endif /* not USE_CALLOC */
253 #if DEBUG > 3 || defined(MEM_ACCT)
254  printf("+%p:%p=(%d)\n", ptr, ptr+size-1, size);
255 #endif /* DEBUG > 3 || MEM_ACCT */
256  memcache[memlast].mmPtr = ptr;
257  memcache[memlast].size = size;
258  (void) strcpy(memcache[memlast].label, name);
259 #ifdef MEM_ACCT
260  printf("memAllocTagged(%d, \"%s\") == %p [entry %04d]\n", size, name, ptr,
261  memlast);
262  /* memCacheDump("post-memAllocTagged:"); */
263 #endif /* MEM_ACCT */
264  return(ptr);
265 }
266 
267 
268 void memFreeTagged(void *ptr, char *note)
269 {
270  struct mm_cache *mmp;
271  int i;
272 
273 #if defined(PROC_TRACE) || defined(MEM_ACCT)
274  traceFunc("== memFree(%p, \"%s\")\n", ptr, note);
275 #endif /* PROC_TRACE || MEM_ACCT */
276 
277 #ifdef MEMORY_TRACING
278  DEBUG("mprobe(%p)\n", ptr)
279  mprobe(ptr); /* see if glibc still likes this memory */
280 #endif /* MEMORY_TRACING */
281  for (mmp = memcache, i = 0; i <= memlast; mmp++, i++) {
282  if (mmp->mmPtr == ptr) {
283 #ifdef MEM_ACCT
284  printf("memFree(%p, \"%s\") is entry %04d (%d bytes)\n", ptr, note, i,
285  mmp->size);
286 #endif /* MEM_ACCT */
287  break;
288  }
289  }
290  if (i > memlast) {
291  LOG_FATAL("Could not locate %p to free!", ptr)
292  Bail(-__LINE__);
293  }
294  free(ptr);
295 #if DEBUG > 3 || defined(MEM_ACCT)
296  printf("-%p=(%d)\n", ptr, mmp->size);
297 #endif /* DEBUG > 3 || MEM_ACCT */
298  if (i != memlast) {
299  (void) memmove(&memcache[i], &memcache[i+1],
300  (memlast-i)*sizeof(struct mm_cache));
301  }
302  memset(&memcache[memlast], 0, sizeof(struct mm_cache));
303  memlast--;
304 #ifdef MEM_ACCT
305  memCacheDump("post-memFree:");
306 #endif /* MEM_ACCT */
307  return;
308 }
309 
310 
311 void memCacheDump(char *s)
312 {
313  struct mm_cache *m;
314  static int first = 1;
315  int i, start;
316  /* */
317  if (s != NULL_STR) {
318  printf("%s\n", s);
319  }
320  if (memlast < 0) {
321  printf("%%%%%% mem-cache is EMPTY\n");
322  return;
323  }
324  start = (memlast > 50 ? memlast-50 : 0);
325  printf("%%%%%% mem-cache @ %p [last=%d]\n", memcache, memlast);
326  for (m = memcache+start, i = start; i <= memlast; m++, i++) {
327  printf("mem-entry %04d: %p (%d) - %s\n", i, m->mmPtr,
328  m->size, m->label);
329  if (!first) {
330  printf("... \"%s\"\n", m->mmPtr);
331  }
332  }
333  printf("%%%%%% mem-cache END\n");
334  if (first) {
335  first --;
336  }
337  return;
338 }
339 #endif /* MEMORY_TRACING */
340 
352 char *findBol(char *s, char *upperLimit)
353 {
354  char *cp;
355 
356 #ifdef PROC_TRACE
357  traceFunc("== findBol(%p, %p)\n", s, upperLimit);
358 #endif /* PROC_TRACE */
359 
360  if (s == NULL_STR || upperLimit == NULL_STR) {
361  return(NULL_STR);
362  }
363  for (cp = s; cp > upperLimit; cp--) {
364 #ifdef DEBUG
365  DEBUG("cp %p upperLimit %p\n", cp, upperLimit)
366 #endif /* DEBUG */
367  if (isEOL(*cp)) {
368 #ifdef DEBUG
369  DEBUG("Got it! BOL == %p\n", cp)
370 #endif /* DEBUG */
371  return((char*)(cp+1));
372  }
373  }
374  if (cp == upperLimit) {
375 #ifdef DEBUG
376  DEBUG("AT upperLimit %p\n", upperLimit);
377 #endif /* DEBUG */
378  return(upperLimit);
379  }
380  return(NULL_STR);
381 }
382 
390 char *findEol(char *s)
391 {
392  char *cp;
393 
394 #ifdef PROC_TRACE
395  traceFunc("== findEol(%p)\n", s);
396 #endif /* PROC_TRACE */
397 
398  if (s == NULL_STR) {
399  return(NULL_STR);
400  }
401  for (cp = s; *cp != NULL_CHAR; cp++) {
402  if (isEOL(*cp)) {
403  return(cp); /* return ptr to EOL or NULL */
404  }
405  }
406  if (*cp == NULL_CHAR) {
407  return(cp);
408  }
409  return(NULL_STR);
410 }
411 
421 void renameInode(char *oldpath, char *newpath)
422 {
423  int err = 0;
424  char sErrorBuf[1024];
425  /*
426  * we die here if the unlink() fails.
427  */
428 
429 #if defined(PROC_TRACE) || defined(UNPACK_DEBUG)
430  traceFunc("== renameInode(%s, %s)\n", oldpath, newpath);
431 #endif /* PROC_TRACE || UNPACK_DEBUG */
432 
433 #ifdef DEBUG
434  (void) mySystem("ls -ldi '%s'", oldpath);
435 #endif /* DEBUG */
436  if (rename(oldpath, newpath) < 0) {
437  if (errno == EXDEV) {
438  err = mySystem("mv '%s' %s", oldpath, newpath);
439  }
440  else {
441  err = 1;
442  }
443  if (err) {
444  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
445  LOG_FATAL("rename(%s, %s) error: %s", oldpath, newpath, sErrorBuf)
446  Bail(-__LINE__);
447  }
448  }
449 #ifdef DEBUG
450  (void) mySystem("ls -ldi %s", newpath);
451 #endif /* DEBUG */
452  return;
453 }
454 
462 void chmodInode(char *pathname, int mode)
463 {
464  char sErrorBuf[1024];
465  /*
466  * we die here if the chmod() fails.
467  */
468 
469 #if defined(PROC_TRACE) || defined(UNPACK_DEBUG)
470  traceFunc("== chmodInode(%s, 0%o)\n", pathname, mode);
471 #endif /* PROC_TRACE || UNPACK_DEBUG */
472 
473  if (chmod(pathname, mode) < 0) {
474  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
475  LOG_FATAL("chmod(\"%s\", 0%o) error: %s", pathname, mode, sErrorBuf)
476  Bail(-__LINE__);
477  }
478  return;
479 }
480 
488 FILE *fopenFile(char *pathname, char *mode)
489 {
490  FILE *fp;
491  char sErrorBuf[1024];
492  /*
493  * we don't track directories opened; we front-end and return what's
494  * given to us. we die here if the fopen() fails.
495  */
496 
497 #ifdef PROC_TRACE
498  traceFunc("== fopenFile(%s, \"%s\")\n", pathname, mode);
499 #endif /* PROC_TRACE */
500 
501  if ((fp = fopen(pathname, mode)) == (FILE *) NULL) {
502  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
503  LOG_FATAL("fopen(%s) error: %s", pathname, sErrorBuf);
504  Bail(-__LINE__);
505  }
506  return(fp);
507 }
508 
509 /*
510  *
511  Save for now, could be useful for debugging
512 
513 static void printListToFile(list_t *l, char *filename, char *mode) {
514  FILE *fp;
515  item_t *ip;
516 
517  fp = fopenFile(filename, mode);
518  while ((ip = listIterate(l)) != NULL_ITEM) {
519  fprintf(fp, "%s\n", ip->str);
520  }
521  (void) fclose(fp);
522  return;
523 }
524  */
525 
533 FILE *popenProc(char *command, char *mode)
534 {
535  FILE *pp;
536  char sErrorBuf[1024];
537  /*
538  * we don't track directories opened; we front-end and return what's
539  * given to us. we die here if the popen() fails.
540  */
541 
542 #ifdef PROC_TRACE
543  traceFunc("== popenProc(\"%s\", %s)\n", command, mode);
544 #endif /* PROC_TRACE */
545 
546  if ((pp = popen(command, mode)) == (FILE *) NULL) {
547 #ifdef MEMORY_TRACING
548  memCacheDump("Post-popen-failure:");
549 #endif /* MEMORY_TRACING */
550  strerror_r(errno, sErrorBuf, sizeof(sErrorBuf));
551  LOG_FATAL("popen(\"%s\") error: %s", command, sErrorBuf)
552  Bail(-__LINE__);
553  }
554  return(pp);
555 }
556 
557 
563 char *wordCount(char *textp)
564 {
565  static char wcbuf[64];
566  int lines;
567  char *cp;
568 
569 #ifdef PROC_TRACE
570  traceFunc("== wordCount(%p)\n", textp);
571 #endif /* PROC_TRACE */
572 
573  lines = 0;
574  for (cp = textp; *cp; cp++) {
575  switch (*cp) {
576  case '\f':
577  break;
578  case '\n':
579  case '\r':
580  case '\v':
581  lines++;
582  break;
583  case ' ':
584  case '\t':
585  break;
586  default:
587  break;
588  }
589  }
590  (void) sprintf(wcbuf, "%d lines", lines);
591  /*
592  * Save these values for use elsewhere, too.
593  */
594  cur.nLines = lines;
595  return(wcbuf);
596 }
597 
605 char *copyString(char *s, char *label)
606 {
607  char *cp;
608  int len;
609 
610 #ifdef PROC_TRACE
611  traceFunc("== copyString(%p, \"%s\")\n", s, label);
612 #endif /* PROC_TRACE */
613 
614  cp = memAlloc(len=(strlen(s)+1), label);
615 #ifdef DEBUG
616  printf("+CS: %d @ %p\n", len, cp);
617 #endif /* DEBUG */
618  (void) strcpy(cp, s);
619  return(cp);
620 }
621 
627 char *pathBasename(char *path)
628 {
629  char *cp;
630 
631 #ifdef PROC_TRACE
632  traceFunc("== pathBasename(\"%s\")\n", path);
633 #endif /* PROC_TRACE */
634 
635  cp = strrchr(path, '/');
636  return(cp == NULL_STR ? path : (char *)(cp+1));
637 }
638 
642 char *getInstances(char *textp, int size, int nBefore, int nAfter, char *regex,
643  int recordOffsets)
644 {
645  int i;
646  int notDone;
647  int buflen = 1;
648  static char *ibuf = NULL;
649  static int bufmax = 0;
650  char *sep = _REGEX(_UTIL_XYZZY);
651  item_t *p;
652  item_t *bp = 0;
653  char *fileeof;
654  char *start;
655  char *end;
656  char *curptr;
657  char *bufmark;
658  char save;
659  char *cp;
660  int newDataLen;
661  int regexFlags = REG_ICASE|REG_EXTENDED;
662 
663 #if defined(PROC_TRACE) || defined(PHRASE_DEBUG) || defined(DOCTOR_DEBUG)
664  traceFunc("== getInstances(%p, %d, %d, %d, \"%s\", %d)\n", textp, size,
665  nBefore, nAfter, regex, recordOffsets);
666 #endif /* PROC_TRACE || PHRASE_DEBUG || DOCTOR_DEBUG */
667 
668  if ((notDone = strGrep(regex, textp, regexFlags)) == 0) {
669 #ifdef PHRASE_DEBUG
670  printf("... no match: 1st strGrep()\n");
671 #endif /* PHRASE_DEBUG */
672  return(NULL_STR);
673  }
674  /*
675  * The global 'offsets list' is indexed by the seed/key (a regex) that we
676  * use for doctoring buffers... each entry will contain a list (containing
677  * the "paragraphs" that match the key) AND its size (e.g., # of 'chunks'),
678  * which also means, if there are N chunks, there are N-1 'xyzzy' separators.
679  */
680  p = listGetItem(&cur.offList, regex);
681  p->seqNo = cur.offList.used;
682  p->nMatch = 0;
683  if (recordOffsets) {
684  if (p->bList) free(p->bList);
685  p->bList = (list_t *)memAlloc(sizeof(list_t), MTAG_LIST);
686  (void) sprintf(utilbuf, "\"%c%c%c%c%c%c%c%c%c%c\" match-list",
687  *regex, *(regex+1), *(regex+2), *(regex+3), *(regex+4),
688  *(regex+5), *(regex+6), *(regex+7), *(regex+8), *(regex+9));
689 #ifdef PHRASE_DEBUG
690  printf("Creating %s\n", utilbuf);
691 #endif /* PHRASE_DEBUG */
692  listInit(p->bList, 0, utilbuf); /* <- MEMORY LEAK from p->bList->items not freed */
693 #ifdef QA_CHECKS
694  p->val3++; /* sanity-check -- should never be >1 ! */
695  if (p->val3 > 1) {
696  LOG_FATAL("Called getInstances(%s) more than once", regex)
697  Bail(-__LINE__);
698  }
699 #endif /* QA_CHECKS */
700  }
701 #ifdef REUSE_STATIC_MEMORY
702  if (ibuf == NULL_STR) { /* first time, uninitialized */
703  ibuf = grepzone;
704  bufmax = sizeof(grepzone);
705  }
706  else if (ibuf != grepzone) {
707  memFree(ibuf, MTAG_DOUBLED); /* free the memory... */
708  ibuf = grepzone; /* ... and reset */
709  bufmax = sizeof(grepzone);
710  }
711 #else /* not REUSE_STATIC_MEMORY */
712  if (ibuf == NULL_STR) {
713  ibuf = memAlloc((bufmax = 1024*1024), MTAG_SEARCHBUF);
714  }
715 #endif /* not REUSE_STATIC_MEMORY */
716  *ibuf = NULL_CHAR;
717  bufmark = ibuf;
718  end = NULL_STR;
719  /*
720  * At this point, we know the string we're looking for is IN the file.
721  */
722 #ifdef PHRASE_DEBUG
723  printf("getInstances: \"%s\" [#1] in buf [%d-%d]\n", regex,
724  cur.regm.rm_so, cur.regm.rm_eo-1);
725  printf("Really in the buffer: [");
726  for (cp = textp + cur.regm.rm_so; cp < (textp + cur.regm.rm_eo); cp++) {
727  printf("%c", *cp);
728  }
729  printf("]\n");
730 #endif /* PHRASE_DEBUG */
731  /*
732  * Find the start of the text line containing the "first" match.
733  * locate start of "$nBefore lines above pattern match"; go up to the
734  * text on the _previous_ line before we 'really start counting'
735  */
736  curptr = textp;
737  fileeof = (char *) (textp+size);
738  while (notDone) { /* curptr is the 'current block' ptr */
739  p->nMatch++;
740 #ifdef PHRASE_DEBUG
741  printf("... found Match #%d\n", p->nMatch);
742 #endif /* PHRASE_DEBUG */
743  if (recordOffsets) {
744  (void) sprintf(utilbuf, "buf%05d", p->nMatch);
745  bp = listGetItem(p->bList, utilbuf);
746  }
747  start = findBol(curptr + cur.regm.rm_so, textp);
748  /*
749  * Go to the beggining of the current line and, if nBefore > 0, go 'up'
750  * in the text "$nBefore" lines. Count 2-consecutive EOL-chars as one
751  * line since some text files use <CR><LF> as line-terminators.
752  */
753  if ((nBefore > 0) && (start > textp)) {
754  for (i = 0; (i < nBefore) && (start > textp); i++) {
755  start -= 2;
756  if ((start > textp) && isEOL(*start)) {
757  start--;
758  }
759  if (start > textp) {
760  start = findBol(start, textp);
761  }
762 #ifdef PHRASE_DEBUG
763  DEBUG("start = %p\n", start)
764 #endif /* PHRASE_DEBUG */
765  }
766  }
767  if (recordOffsets) {
768  bp->bStart = start-textp;
769  }
770  /*
771  * Now do what "grep -A $nAfter _filename+" does.
772  *****
773  * If nAfter == 0, we want the end of the current line.
774  *****
775  * If nAfter > 0, locate the end of the line of LAST occurrence of the
776  * string within the next $nAfter lines. Not well-worded, you say?
777  *****
778  * E.g., if we're saving SIX lines below and we see our pattern 4 lines
779  * below the first match then we'll save 10 lines from the first match.
780  * And to continue this example, if we then see our pattern 9 lines from
781  * the start of the buffer (since we're looking up to 10 lines now), we
782  * will save *15* lines. Repeat until the last 6 lines we save DO NOT
783  * have our pattern.
784  */
785  do {
786  curptr += cur.regm.rm_eo;
787  end = findEol(curptr);
788  if (end < fileeof) {
789  end++; /* first char past end-of-line */
790  }
791  if (nAfter > 0) {
792  for (i = 0; end < fileeof; end++) {
793  if (isEOL(*end)) { /* double-EOL */
794  end++; /* <CR><LF>? */
795  }
796  end = findEol(end);
797  if (end == NULL_STR) {
798  LOG_FATAL("lost the end-of-line")
799  Bail(-__LINE__);
800  }
801  if (*end == NULL_CHAR) {
802  break; /* EOF == done */
803  }
804  if (++i == nAfter) {
805  break;
806  }
807  }
808  if ((end < fileeof) && *end) {
809  end++; /* past newline-char */
810  }
811  }
812 #ifdef PHRASE_DEBUG
813  printf("Snippet, with %d lines below:\n----\n", nAfter);
814  for (cp = start; cp < end; cp++) {
815  printf("%c", *cp);
816  }
817  printf("====\n");
818 #endif /* PHRASE_DEBUG */
819  notDone = strGrep(regex, curptr, regexFlags);
820  if (notDone) { /* another match? */
821 #ifdef PHRASE_DEBUG
822  printf("... next match @ %d:%d (end=%d)\n",
823  curptr - textp + cur.regm.rm_so,
824  curptr - textp + cur.regm.rm_eo - 1, end - textp);
825 #endif /* PHRASE_DEBUG */
826 #ifdef QA_CHECKS
827  if ((curptr + cur.regm.rm_eo) > fileeof) {
828  Assert(YES, "Too far into file!");
829  }
830 #endif /* QA_CHECKS */
831  /* next match OUTSIDE the text we've already saved? */
832  if ((curptr + cur.regm.rm_eo) > end) {
833  break;
834  }
835  /* else, next match IS within the text we're looking at! */
836  }
837  } while (notDone);
838  /*
839  * Add this block of text to our buffer. If 'notdone' is true, there's
840  * at least one more block of text that goes in the buffer, so add the
841  * block-o-text-separator, too. And, make sure we don't overflow our
842  * buffer (BEFORE we modify it); we don't KNOW how much text to expect!
843  */
844  save = *end;
845  *end = NULL_CHAR; /* char PAST the newline! */
846  if (recordOffsets) {
847  bp->bLen = end-start;
848  bp->buf = copyString(start, MTAG_TEXTPARA);
849  bp->bDocLen = 0;
850 #ifdef PHRASE_DEBUG
851  printf("%s starts @%d, len %d ends [%c%c%c%c%c%c%c]\n",
852  utilbuf, bp->bStart, bp->bLen, *(end-8), *(end-7),
853  *(end-6), *(end-5), *(end-4), *(end-3), *(end-2));
854 #endif /* PHRASE_DEBUG */
855  }
856  newDataLen = end-start+(notDone ? strlen(sep)+1 : 0);
857  while (buflen+newDataLen > bufmax) {
858  char *new;
859 #ifdef QA_CHECKS
860  Assert(NO, "data(%d) > bufmax(%d)", buflen+newDataLen,
861  bufmax);
862 #endif /* QA_CHECKS */
863  bufmax *= 2;
864 #ifdef MEMSTATS
865  printf("... DOUBLE search-pattern buffer (%d -> %d)\n",
866  bufmax/2, bufmax);
867 #endif /* MEMSTATS */
868  new = memAlloc(bufmax, MTAG_DOUBLED);
869  (void) memcpy(new, ibuf, buflen);
870 #if 0
871  printf("REPLACING buf %p(%d) with %p(%d)\n", ibuf,
872  bufmax/2, new, bufmax);
873 #endif
874 #ifdef REUSE_STATIC_MEMORY
875  if (ibuf != grepzone) {
876  memFree(ibuf, MTAG_TOOSMALL);
877  }
878 #else /* not REUSE_STATIC_MEMORY */
879  memFree(ibuf, MTAG_TOOSMALL);
880 #endif /* not REUSE_STATIC_MEMORY */
881  ibuf = new;
882  }
883  cp = bufmark = ibuf+buflen-1; /* where the NULL is _now_ */
884  buflen += newDataLen; /* new end-of-data ptr */
885  bufmark += sprintf(bufmark, "%s", start);
886  if (notDone) {
887  bufmark += sprintf(bufmark, "%s\n", sep);
888  }
889  /*
890  * Some files use ^M as a line-terminator, so we need to convert those
891  * control-M's to 'regular newlines' in case we need to use the regex
892  * stuff on this buffer; the regex library apparently doesn't have a
893  * flag for interpretting ^M as end-of-line character.
894  */
895  while (*cp) {
896  if (*cp == '\r') { /* '\015'? */
897  *cp = '\n'; /* '\012'! */
898  }
899  cp++;
900  }
901  *end = save;
902 #ifdef PHRASE_DEBUG
903  printf("Loop end, BUF IS NOW: [\"%s\":%d]\n----\n%s====\n",
904  regex, strlen(ibuf), ibuf);
905 #endif /* PHRASE_DEBUG */
906  }
907 
908 #if defined(PHRASE_DEBUG) || defined(DOCTOR_DEBUG)
909  printf("getInstances(\"%s\"): Found %d bytes of data...\n", regex,
910  buflen-1);
911 #endif /* PHRASE_DEBUG || DOCTOR_DEBUG */
912 #ifdef PHRASE_DEBUG
913  printf("getInstances(\"%s\"): buffer %p --------\n%s\n========\n",
914  regex, ibuf, ibuf);
915 #endif /* PHRASE_DEBUG */
916 
917  return(ibuf);
918 }
919 
925 char *curDate()
926 {
927  static char datebuf[32];
928  char *cp;
929  time_t thyme;
930 
931  (void) time(&thyme);
932  (void) ctime_r(&thyme, datebuf);
933  if ((cp = strrchr(datebuf, '\n')) == NULL_STR) {
934  LOG_FATAL("Unexpected time format from ctime_r()!")
935  Bail(-__LINE__);
936  }
937  *cp = NULL_CHAR;
938  return(datebuf);
939 }
940 
941 
942 #ifdef MEMSTATS
943 void memStats(char *s)
944 {
945  static int first = 1;
946  static char mbuf[128];
947 
948  if (first) {
949  first = 0;
950  sprintf(mbuf, "grep VmRSS /proc/%d/status", getpid());
951  }
952  if (s && *s) {
953  int i;
954  printf("%s: ", s);
955  for (i = (int) (strlen(s)+2); i < 50; i++) {
956  printf(" ");
957  }
958  }
959  (void) mySystem(mbuf);
960 #if 0
961  system("grep Vm /proc/self/status");
962  system("grep Brk /proc/self/status");
963 #endif
964 }
965 #endif /* MEMSTATS */
966 
967 
972 void makeSymlink(char *path)
973 {
974 #if defined(PROC_TRACE) || defined(UNPACK_DEBUG)
975  traceFunc("== makeSymlink(%s)\n", path);
976 #endif /* PROC_TRACE || UNPACK_DEBUG */
977 
978  (void) sprintf(cmdBuf, ".%s", strrchr(path, '/'));
979  if (symlink(path, cmdBuf) < 0) {
980  perror(cmdBuf);
981  LOG_FATAL("Failed: symlink(%s, %s)", path, cmdBuf)
982  Bail(-__LINE__);
983  }
984  return;
985 }
986 
987 
998 void printRegexMatch(int n, int cached)
999 {
1000  int save_so;
1001  int save_eo;
1002  int match;
1003  static char debugStr[256];
1004  static char misc[64];
1005  char *cp;
1006  char *x = NULL;
1007  char *textp;
1008 
1009 #ifdef PROC_TRACE
1010  traceFunc("== printRegexMatch(%d, %d)\n", n, cached);
1011 #endif /* PROC_TRACE */
1012 
1013  if (*debugStr == NULL_CHAR) {
1014  strncpy(debugStr, gl.initwd, sizeof(debugStr)-1);
1015  strncat(debugStr, "/Nomos.strings.txt", sizeof(debugStr)-1);
1016 #ifdef DEBUG
1017  printf("File: %s\n", debugStr);
1018 #endif /* DEBUG */
1019  }
1020  save_so = cur.regm.rm_so;
1021  save_eo = cur.regm.rm_eo;
1022  if (isFILE(debugStr)) {
1023  if ((match = (gl.flags & FL_SAVEBASE))) { /* assignment is deliberate */
1024  gl.flags &= ~FL_SAVEBASE;
1025  }
1026 #ifdef DEBUG
1027  printf("Match [%d:%d]\n", save_so, save_eo);
1028 #endif /* DEBUG */
1029  textp = mmapFile(debugStr);
1030  (void) sprintf(misc, "=#%03d", n);
1031  if (strGrep(misc, textp, REG_EXTENDED)) {
1032 #ifdef DEBUG
1033  printf("Patt: %s\nMatch: %d:%d\n", misc,
1034  cur.regm.rm_so, cur.regm.rm_eo);
1035 #endif /* DEBUG */
1036  x = textp + cur.regm.rm_so;
1037  cp = textp + cur.regm.rm_so;
1038  *x = NULL_CHAR;
1039  while (*--x != '[') {
1040  if (x == textp) {
1041  LOG_FATAL("Cannot locate debug symbol")
1042  Bail(-__LINE__);
1043  }
1044  }
1045  ++x; /* CDB - Moved from line below. Hope this is what was intended.*/
1046  (void) strncpy(misc, x, cp - x); /* CDB - Fix */
1047  misc[cp-x] = NULL_CHAR;
1048  } else {
1049  (void) strcpy(misc, "?");
1050  }
1051  munmapFile(textp);
1052  if (match) {
1053  gl.flags |= FL_SAVEBASE;
1054  }
1055 #ifdef DEBUG
1056  printf("RESTR [%d:%d]\n", cur.regm.rm_so, cur.regm.rm_eo);
1057 #endif /* DEBUG */
1058  }
1059  cur.regm.rm_so = save_so;
1060  cur.regm.rm_eo = save_eo;
1061  printf("%s regex %d ", cached ? "Cached" : "Found", n);
1062  if (x) {
1063  printf("(%s) ", misc);
1064  }
1065  if (!cached) {
1066  printf("\"%s\"", _REGEX(n));
1067  }
1068  printf("\n");
1069 #ifdef DEBUG
1070  printf("Seed: \"%s\"\n", _SEED(n));
1071 #endif /* DEBUG */
1072  return;
1073 }
1074 
1080 void ReplaceNulls(char *Buffer, int BufferSize)
1081 {
1082  char *pBuf;
1083 
1084  for (pBuf = Buffer; BufferSize--; pBuf++)
1085  if (*pBuf == 0) *pBuf = ' ';
1086 }
1087 
1094 char *mmapFile(char *pathname) /* read-only for now */
1095 {
1096  struct mm_cache *mmp;
1097  int i;
1098  int n;
1099  int rem;
1100  char *cp;
1101 
1102 #ifdef PROC_TRACE
1103  traceFunc("== mmapFile(%s)\n", pathname);
1104 #endif /* PROC_TRACE */
1105 
1106  for (mmp = mmap_data, i = 0; i < MM_CACHESIZE; i++, mmp++) {
1107  if (mmp->inUse == 0) {
1108  break;
1109  }
1110  }
1111 
1112  if (i == MM_CACHESIZE) {
1113  printf("mmap-cache too small [%d]!\n", MM_CACHESIZE);
1114  mmapOpenListing();
1115  Bail(12);
1116  }
1117 
1118  if ((mmp->fd = open(pathname, O_RDONLY)) < 0) {
1119  if (errno == ENOENT) {
1120  mmp->inUse = 0; /* overkill? */
1121  mmp->size = -1; /* overkill? */
1122  mmp->mmPtr = (void *) NULL;
1123 #if (DEBUG > 3)
1124  printf("mmapFile: ENOENT %s\n", pathname);
1125 #endif /* DEBUG > 3 */
1126  return(NULL_STR);
1127  }
1128  perror(pathname);
1129  (void) mySystem("ls -l %s", pathname);
1130  LOG_FATAL("%s: open failure!", pathname)
1131  Bail(-__LINE__);
1132  }
1133 
1134  if (fstat(mmp->fd, &cur.stbuf) < 0) {
1135  printf("fstat failure!\n");
1136  perror(pathname);
1137  Bail(13);
1138  }
1139  if (S_ISDIR(cur.stbuf.st_mode)) {
1140  printf("mmapFile(%s): is a directory\n", pathname);
1141  Bail(14);
1142  }
1143 
1144  (void) strcpy(mmp->label, pathname);
1145  if (cur.stbuf.st_size)
1146  {
1147  mmp->size = cur.stbuf.st_size + 1;
1148  mmp->mmPtr = memAlloc(mmp->size, MTAG_MMAPFILE);
1149 #ifdef DEBUG
1150  printf("+MM: %lu @ %p\n", mmp->size, mmp->mmPtr);
1151 #endif /* DEBUG */
1152 
1153  /* Limit scan to first MAX_SCANBYTES
1154  * We have never found a license more than 64k into a file.
1155  */
1156 // if (cur.stbuf.st_size > MAX_SCANBYTES) mmp->size = MAX_SCANBYTES;
1157  if (mmp->size > MAX_SCANBYTES) mmp->size = MAX_SCANBYTES;
1158 
1159 
1160  rem = mmp->size-1;
1161  cp = mmp->mmPtr;
1162  while (rem > 0) {
1163  if ((n = (int) read(mmp->fd, cp, (size_t) rem)) < 0) {
1164  /* log error and move on. This way error will be logged
1165  * but job will continue
1166  */
1167  LOG_WARNING("nomos read error: %s, file: %s, read size: %d, pfile_pk: %ld\n", strerror(errno), pathname, rem, cur.pFileFk);
1168  break;
1169  }
1170  rem -= n;
1171  cp += n;
1172  }
1173  mmp->inUse = 1;
1174  /* Replace nulls with blanks so binary files can be scanned */
1175  ReplaceNulls(mmp->mmPtr, mmp->size-1);
1176  return((char *) mmp->mmPtr);
1177  }
1178  /*
1179  * If we're here, we hit some sort of error.
1180  */
1181  (void) close(mmp->fd);
1182 #ifdef QA_CHECKS
1183  Assert(NO, "mmapFile: returning NULL");
1184 #endif /* QA_CHECKS */
1185  return(NULL_STR);
1186 }
1187 
1188 
1189 void mmapOpenListing()
1190 {
1191  struct mm_cache *mmp;
1192  int i;
1193 
1194  printf("=== mm-cache BEGIN ===\n");
1195  for (mmp = mmap_data, i = 0; i < MM_CACHESIZE; i++, mmp++) {
1196  if (mmp->inUse) {
1197  printf("mm[%d]: (%d) %s:%d\n", i, mmp->fd,
1198  mmp->label, (int) mmp->size);
1199  }
1200  }
1201  printf("--- mm-cache END ---\n");
1202  return;
1203 }
1204 
1209 void munmapFile(void *ptr)
1210 {
1211  struct mm_cache *mmp;
1212  int i;
1213 
1214 #ifdef PROC_TRACE
1215  traceFunc("== munmapFile(%p)\n", ptr);
1216 #endif /* PROC_TRACE */
1217 
1218  if (ptr == (void *) NULL) {
1219 #ifdef QA_CHECKS
1220  Assert(NO, "NULL sent to munmapFile()!");
1221 #endif /* QA_CHECKS */
1222  return;
1223  }
1224  for (mmp = mmap_data, i = 0; i < MM_CACHESIZE; i++, mmp++) {
1225  if (mmp->inUse == 0) {
1226  continue;
1227  }
1228  if (mmp->mmPtr == ptr) {
1229 #if DEBUG > 4
1230  printf("munmapFile: clearing entry %d\n", i);
1231 #endif /* DEBUG > 4 */
1232 #if 0
1233  if (mmp->size) {
1234  (void) munmap((void *) ptr, (size_t) mmp->size);
1235  }
1236 #endif
1237  if (close(mmp->fd) < 0) {
1238  perror("close");
1239  Bail(16);
1240  }
1241 #ifdef PARANOID
1242  mmp->buf = (void *) NULL;
1243 #endif /* PARANOID */
1244  mmp->inUse = 0;
1245 #ifdef DEBUG
1246  printf("DEBUG: munmapFile: freeing %lu bytes\n",
1247  mmp->size);
1248 #endif /* DEBUG */
1249  memFree(mmp->mmPtr, MTAG_MMAPFILE);
1250  break;
1251  }
1252  }
1253  return;
1254 }
1255 
1265 int bufferLineCount(char *p, int len)
1266 {
1267  char *cp;
1268  char *eofaddr = NULL;
1269  int i;
1270 
1271 #ifdef PROC_TRACE
1272  traceFunc("== bufferLineCount(%p, %d)\n", p, len);
1273 #endif /* PROC_TRACE */
1274 
1275  if (eofaddr == p) {
1276  return(0);
1277  }
1278  eofaddr = (char *) (p+len);
1279  for (i = 0, cp = p; cp <= eofaddr; cp++, i++) {
1280  if ((cp = findEol(cp)) == NULL_STR || *cp == NULL_CHAR) {
1281  break;
1282  }
1283  }
1284 #if (DEBUG > 3)
1285  printf("bufferLineCount == %d\n", i);
1286 #endif /* DEBUG > 3 */
1287  return(i ? i : 1);
1288 }
1289 
1295 void appendFile(char *pathname, char *str)
1296 {
1297  FILE *fp;
1298 
1299 #ifdef PROC_TRACE
1300  traceFunc("== appendFile(%s, \"%s\")\n", pathname, str);
1301 #endif /* PROC_TRACE */
1302 
1303  fp = fopenFile(pathname, "a+");
1304  fprintf(fp, "%s\n", str);
1305  (void) fclose(fp);
1306  return;
1307 }
1308 
1315 int mySystem(const char *fmt, ...)
1316 {
1317  int ret;
1318  va_start(ap, fmt);
1319  (void) vsprintf(cmdBuf, fmt, ap);
1320  va_end(ap);
1321 
1322 #if defined(PROC_TRACE) || defined(UNPACK_DEBUG)
1323  traceFunc("== mySystem('%s')\n", cmdBuf);
1324 #endif /* PROC_TRACE || UNPACK_DEBUG */
1325 
1326  ret = system(cmdBuf);
1327  if (WIFEXITED(ret)) {
1328  ret = WEXITSTATUS(ret);
1329 #ifdef DEBUG
1330  if (ret) {
1331  LOG_ERROR("system(%s) returns %d", cmdBuf, ret)
1332  }
1333 #endif /* DEBUG */
1334  }
1335  else if (WIFSIGNALED(ret)) {
1336  ret = WTERMSIG(ret);
1337  LOG_ERROR("system(%s) died from signal %d", cmdBuf, ret)
1338  }
1339  else if (WIFSTOPPED(ret)) {
1340  ret = WSTOPSIG(ret);
1341  LOG_ERROR("system(%s) stopped, signal %d", cmdBuf, ret)
1342  }
1343  return(ret);
1344 }
1345 
1346 
1352 int isFILE(char *pathname)
1353 {
1354 
1355 #ifdef PROC_TRACE
1356  traceFunc("== isFILE(%s)\n", pathname);
1357 #endif /* PROC_TRACE */
1358 
1359  return(isINODE(pathname, S_IFREG));
1360 }
1361 
1362 
1370 int addEntry(char *pathname, int forceFlag, const char *fmt, ...)
1371 {
1372  va_start(ap, fmt);
1373  vsprintf(utilbuf, fmt, ap);
1374  va_end(ap);
1375 
1376 #ifdef PROC_TRACE
1377  traceFunc("== addEntry(%s, %d, \"%s\")\n", pathname, forceFlag, utilbuf);
1378 #endif /* PROC_TRACE */
1379 
1380  if (pathname == NULL_STR) {
1381  Assert(YES, "addEntry - NULL pathname");
1382  }
1383  if (forceFlag || !lineInFile(pathname, utilbuf)) {
1384  appendFile(pathname, utilbuf);
1385  return(1);
1386  }
1387  return(0);
1388 }
1389 
1394 void Msg(const char *fmt, ...)
1395 {
1396  va_start(ap, fmt);
1397  (void) vprintf(fmt, ap);
1398  va_end(ap);
1399  return;
1400 }
1401 
1407 void Assert(int fatalFlag, const char *fmt, ...)
1408 {
1409  va_start(ap, fmt);
1410  (void) sprintf(utilbuf, "ASSERT: ");
1411  (void) vsprintf(utilbuf+strlen(utilbuf), fmt, ap);
1412  va_end(ap);
1413 
1414 #ifdef PROC_TRACE
1415  traceFunc("!! Assert(\"%s\")\n", utilbuf+strlen(gl.progName)+3);
1416 #endif /* PROC_TRACE */
1417 
1418  (void) strcat(utilbuf, "\n");
1419  Msg("%s", utilbuf);
1420  if (fatalFlag) {
1421  Bail(17);
1422  }
1423  return;
1424 }
1425 
1426 
1427 void traceFunc(char *fmtStr, ...)
1428 {
1429  va_list args;
1430 
1431 #ifdef PROC_TRACE_SWITCH
1432  if (gl.ptswitch)
1433 #endif /* PROC_TRACE_SWITCH */
1434  va_start(args, fmtStr);
1435 
1436  vprintf(fmtStr, args);
1437  va_end(args);
1438 #ifdef PROC_TRACE_SWITCH
1439 }
1440 #endif /* PROC_TRACE_SWITCH */
1441 }
1442 
1443 
1444 #ifdef MEM_DEBUG
1445 char *memAllocLogged(int size)
1446 {
1447  register void *ptr;
1448  /* */
1449  ptr = calloc(size, 1);
1450  printf("%p = calloc( %d , 1 )\n", ptr, size);
1451  return(ptr);
1452 }
1453 
1454 void memFreeLogged(void *ptr)
1455 {
1456  printf("free( %p )\n", ptr);
1457  free(ptr);
1458  return;
1459 }
1460 #endif /* MEM_DEBUG */
int isFILE(char *pathname)
Check if an inode is a file.
Definition: util.c:1352
#define YES
Definition: nomos.h:188
int isEMPTYFILE(char *fpath)
Check if given file is empty.
Definition: util.c:77
char * curDate()
Get the current date.
Definition: util.c:925
Store the results of a regex match.
Definition: scanners.hpp:39
tricky data structure used for a list of &#39;items&#39;
Definition: nomos.h:287
void chmodInode(char *pathname, int mode)
Change inode mode bits.
Definition: util.c:462
int used
Definition: nomos.h:323
int s
The socket that the CLI will use to communicate.
Definition: fo_cli.c:48
char * wordCount(char *textp)
VERY simple line count, does NOT have to be perfect!
Definition: util.c:563
void ReplaceNulls(char *Buffer, int BufferSize)
Replace all nulls in Buffer with blanks.
Definition: util.c:1080
int bufferLineCount(char *p, int len)
Finds the length of first line in a buffer.
Definition: util.c:1265
void Bail(int exitval)
Close connections and exit.
Definition: nomos_utils.c:541
char * getInstances(char *textp, int size, int nBefore, int nAfter, char *regex, int recordOffsets)
Get occurrence of a regex in a given string pointer.
Definition: util.c:642
#define memFree(x, y)
Definition: nomos.h:544
int isCHAR(char *cpath)
Check if given path is a character device.
Definition: util.c:110
void listInit(list_t *l, int size, char *label)
intialize a list, if the list is not empty, empty it (initialize it to zero&#39;s).
Definition: list.c:67
char initwd[myBUFSIZ]
CDB, would like to workaround/eliminate.
Definition: nomos.h:358
item_t * listGetItem(list_t *l, char *s)
get an item from the itemlist. If the item is not in the itemlist, then add it to the itemlist...
Definition: list.c:259
int lineInFile(char *pathname, char *regex)
Check if a line exists in a file.
Definition: nomos_regex.c:92
void Msg(const char *fmt,...)
DO NOT automatically add to a string passed to Msg(); in parseDistro, we sometimes want to dump a p...
Definition: util.c:1394
int addEntry(char *pathname, int forceFlag, const char *fmt,...)
adds a line to the specified pathname
Definition: util.c:1370
int flags
Flags.
Definition: nomos.h:361
#define NULL_CHAR
NULL character.
Definition: nomos.h:247
#define MM_CACHESIZE
MM Cache size.
Definition: util.c:34
void Assert(int fatalFlag, const char *fmt,...)
Raise an assert.
Definition: util.c:1407
start($application)
start the application Assumes application is restartable via /etc/init.d/<script>. The application passed in should match the script name in /etc/init.d
Definition: pkgConfig.php:1225
#define _REGEX(x)
Definition: nomos.h:460
char debugStr[myBUFSIZ]
Debug string.
Definition: nomos.h:159
unsigned long size
Size.
Definition: nomos.h:268
int inUse
Cache in use.
Definition: nomos.h:266
#define MAX_RENAME
Max rename length.
Definition: nomos.h:137
void printRegexMatch(int n, int cached)
CDB – Need to review this code, particularly for the use of an external file (Nomos.strings.txt). Despite the fact that variable is named debugStr, the file appears to be used for more than just debugging.
Definition: util.c:998
char * mmapFile(char *pathname)
Blarg. Files that are EXACTLY a multiple of the system pagesize do not get a NULL on the end of the b...
Definition: util.c:1094
#define isEOL(x)
Check if x points to a EOL character.
Definition: nomos.h:253
int fd
File descriptor.
Definition: nomos.h:267
char * copyString(char *s, char *label)
Create a copy of a string.
Definition: util.c:605
char * pathBasename(char *path)
Get the basename from a file path.
Definition: util.c:627
int isSYMLINK(char *spath)
Check if given path is a symbolic link.
Definition: util.c:140
int isDIR(char *dpath)
Check if given path is a directory.
Definition: util.c:62
#define MAX_SCANBYTES
Definition: nomos.h:144
int mySystem(const char *fmt,...)
Run a system command.
Definition: util.c:1315
void renameInode(char *oldpath, char *newpath)
Rename an inode at oldpath to newpath.
Definition: util.c:421
char label[myBUFSIZ]
Label.
Definition: nomos.h:270
#define NULL_STR
NULL string.
Definition: nomos.h:248
int isBLOCK(char *bpath)
Check if given path is a Block device.
Definition: util.c:95
#define _SEED(x)
Definition: nomos.h:464
list_t type structure used to keep various lists. (e.g. there are multiple lists).
Definition: nomos.h:321
int strGrep(char *regex, char *data, int flags)
General-purpose grep function, used for one-time-only searches.
Definition: nomos_regex.c:150
char * findEol(char *s)
Find first ROL in a string.
Definition: util.c:390
#define FL_SAVEBASE
Definition: nomos.h:168
Nomos header file.
int isPIPE(char *ppath)
Check if given path is a pipe.
Definition: util.c:125
int isINODE(char *ipath, int typ)
Check for a inode against a flag.
Definition: util.c:155
void munmapFile(void *ptr)
Definition: util.c:1209
void appendFile(char *pathname, char *str)
Append a string at the end of the file.
Definition: util.c:1295
char * findBol(char *s, char *upperLimit)
Find Begin of Line in a string.
Definition: util.c:352
void * mmPtr
Memory pointer.
Definition: nomos.h:269
#define NO
Definition: nomos.h:184
void * buf
Definition: nomos.h:292
void makeSymlink(char *path)
Create symbolic links for a given path in current directory.
Definition: util.c:972
FILE * fopenFile(char *pathname, char *mode)
Open a file and return the file pointer.
Definition: util.c:488
long pFileFk
Definition: nomos.h:409
FILE * popenProc(char *command, char *mode)
Open a process pipe using popen()
Definition: util.c:533
char * newReloTarget(char *basename)
Check if a relocation target is accessible.
Definition: util.c:187
char progName[64]
Program name.
Definition: nomos.h:359