Changeset 88


Ignore:
Timestamp:
03/06/07 20:35:18 (17 years ago)
Author:
tim
Message:

Fixed a lazy NULL printing to work properly on Solaris.

Switched reglookup exit codes to more standard ones.

Changed Makefile to default to using -liconv except on Linux, since Solaris needs this too.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r81 r88  
    1111
    1212CC=gcc
    13 OPTS=-std=gnu89 -pedantic -Wall -ggdb
     13OPTS=-std=gnu89 -pedantic -Wall
    1414INC=-I/usr/local/include
    1515LIB=-L/usr/local/lib
    1616
    1717UNAME := $(shell uname)
    18 ifeq ($(UNAME),FreeBSD)         
     18ifneq ($(UNAME),Linux
    1919  LIB:=$(LIB) -liconv
    2020endif
  • trunk/src/reglookup.c

    r85 r88  
    2424
    2525#include <stdlib.h>
     26#include <sysexits.h>
    2627#include <stdio.h>
    2728#include <string.h>
     
    409410      copy = (char*)malloc((next-cur+1)*sizeof(char));
    410411      if(copy == NULL)
    411         bailOut(2, "ERROR: Memory allocation problem.\n");
     412        bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
    412413         
    413414      memcpy(copy, cur, next-cur);
     
    417418        ret_val[ret_cur] = NULL;
    418419      else
    419         bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
     420        bailOut(EX_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
    420421    }
    421422    cur = next+1;
     
    430431      ret_val[ret_cur] = NULL;
    431432    else
    432       bailOut(2, "ERROR: Registry maximum depth exceeded.\n");
     433      bailOut(EX_DATAERR, "ERROR: Registry maximum depth exceeded.\n");
    433434  }
    434435
     
    575576   */
    576577  quoted_name = quote_string(vk->valuename, common_special_chars);
     578  if (quoted_name == NULL)
     579  {
     580    quoted_name = malloc(1*sizeof(char));
     581    if(quoted_name == NULL)
     582      bailOut(EX_OSERR, "ERROR: Could not allocate sufficient memory.\n");
     583    quoted_name[0] = '\0';
     584  }
    577585
    578586  if(quoted_value == NULL)
     
    693701 
    694702  if(root == NULL)
    695     bailOut(3, "ERROR: root cannot be NULL.\n");
     703    bailOut(EX_DATAERR, "ERROR: root cannot be NULL.\n");
    696704 
    697705  do
     
    701709      path = iter2Path(iter);
    702710      if(path == NULL)
    703         bailOut(2, "ERROR: Could not construct iterator's path.\n");
     711        bailOut(EX_OSERR, "ERROR: Could not construct iterator's path.\n");
    704712     
    705713      if(!type_filter_enabled || (key_type == type_filter))
     
    717725        /* We're done with this sub-tree, going up and hitting other branches. */
    718726        if(!regfi_iterator_up(iter))
    719           bailOut(3, "ERROR: could not traverse iterator upward.\n");
     727          bailOut(EX_DATAERR, "ERROR: could not traverse iterator upward.\n");
    720728       
    721729        cur = regfi_iterator_cur_key(iter);
    722730        if(cur == NULL)
    723           bailOut(3, "ERROR: unexpected NULL for key.\n");
     731          bailOut(EX_DATAERR, "ERROR: unexpected NULL for key.\n");
    724732       
    725733        sub = regfi_iterator_next_subkey(iter);
     
    732740       */
    733741      if(!regfi_iterator_down(iter))
    734         bailOut(3, "ERROR: could not traverse iterator downward.\n");
     742        bailOut(EX_DATAERR, "ERROR: could not traverse iterator downward.\n");
    735743
    736744      cur = sub;
     
    802810
    803811    if((value == NULL) || (tmp_path_joined == NULL))
    804       bailOut(2, "ERROR: Unexpected error before printValue.\n");
     812      bailOut(EX_OSERR, "ERROR: Unexpected error before printValue.\n");
    805813
    806814    printValue(value, tmp_path_joined);
     
    816824
    817825    if(!regfi_iterator_down(iter))
    818       bailOut(2, "ERROR: Unexpected error on traversing path filter key.\n");
     826      bailOut(EX_DATAERR, "ERROR: Unexpected error on traversing path filter key.\n");
    819827
    820828    return 2;
     
    858866  {
    859867    usage();
    860     bailOut(1, "ERROR: Requires at least one argument.\n");
     868    bailOut(EX_USAGE, "ERROR: Requires at least one argument.\n");
    861869  }
    862870 
     
    869877      {
    870878        usage();
    871         bailOut(1, "ERROR: '-p' option requires parameter.\n");
     879        bailOut(EX_USAGE, "ERROR: '-p' option requires parameter.\n");
    872880      }
    873881      if((path_filter = strdup(argv[argi])) == NULL)
    874         bailOut(2, "ERROR: Memory allocation problem.\n");
     882        bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
    875883
    876884      path_filter_enabled = true;
     
    881889      {
    882890        usage();
    883         bailOut(1, "ERROR: '-t' option requires parameter.\n");
     891        bailOut(EX_USAGE, "ERROR: '-t' option requires parameter.\n");
    884892      }
    885893      if((type_filter = regfi_type_str2val(argv[argi])) < 0)
    886894      {
    887895        fprintf(stderr, "ERROR: Invalid type specified: %s.\n", argv[argi]);
    888         bailOut(1, "");
     896        bailOut(EX_USAGE, "");
    889897      }
    890898      type_filter_enabled = true;
     
    904912      usage();
    905913      fprintf(stderr, "ERROR: Unrecognized option: %s\n", argv[argi]);
    906       bailOut(1, "");
     914      bailOut(EX_USAGE, "");
    907915    }
    908916  }
    909917  if((registry_file = strdup(argv[argi])) == NULL)
    910     bailOut(2, "ERROR: Memory allocation problem.\n");
     918    bailOut(EX_OSERR, "ERROR: Memory allocation problem.\n");
    911919
    912920  f = regfi_open(registry_file);
     
    914922  {
    915923    fprintf(stderr, "ERROR: Couldn't open registry file: %s\n", registry_file);
    916     bailOut(3, "");
     924    bailOut(EX_NOINPUT, "");
    917925  }
    918926
    919927  iter = regfi_iterator_new(f);
    920928  if(iter == NULL)
    921     bailOut(3, "ERROR: Couldn't create registry iterator.\n");
     929    bailOut(EX_OSERR, "ERROR: Couldn't create registry iterator.\n");
    922930
    923931  if(print_header)
     
    942950      printKeyTree(iter);
    943951    else if(retr_path_ret != 0)
    944       bailOut(4, "ERROR: Unknown error occurred in retrieving path.\n");
     952      bailOut(EX_DATAERR, "ERROR: Unknown error occurred in retrieving path.\n");
    945953  }
    946954  else
Note: See TracChangeset for help on using the changeset viewer.