(root)/
util-linux-2.39/
tests/
helpers/
test_pathnames.c
       1  /*
       2   * Copyright (C) 2007 Karel Zak <kzak@redhat.com>
       3   *
       4   * This file is part of util-linux.
       5   *
       6   * This file is free software; you can redistribute it and/or modify
       7   * it under the terms of the GNU General Public License as published by
       8   * the Free Software Foundation; either version 2 of the License, or
       9   * (at your option) any later version.
      10   *
      11   * This file is distributed in the hope that it will be useful,
      12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14   * GNU General Public License for more details.
      15   */
      16  
      17  #include <stdio.h>
      18  #include <stdlib.h>
      19  #include <string.h>
      20  #include <unistd.h>
      21  
      22  #include "pathnames.h"
      23  
      24  struct hlpPath
      25  {
      26  	const char *name;
      27  	const char *path;
      28  };
      29  
      30  #define DEF_HLPPATH(_p)		{ #_p, _p }
      31  
      32  static struct hlpPath paths[] =
      33  {
      34  	DEF_HLPPATH(_PATH_DEFPATH),
      35  	DEF_HLPPATH(_PATH_DEFPATH_ROOT),
      36  	DEF_HLPPATH(_PATH_DEV_LOOP),
      37  	DEF_HLPPATH(_PATH_HUSHLOGIN),
      38  	DEF_HLPPATH(_PATH_MAILDIR),
      39  	DEF_HLPPATH(_PATH_MOTDFILE),
      40  	DEF_HLPPATH(_PATH_NOLOGIN),
      41  	DEF_HLPPATH(_PATH_LOGIN),
      42  	DEF_HLPPATH(_PATH_PASSWD),
      43  	DEF_HLPPATH(_PATH_GSHADOW),
      44  	DEF_HLPPATH(_PATH_GROUP),
      45  	DEF_HLPPATH(_PATH_SHADOW_PASSWD),
      46  	DEF_HLPPATH(_PATH_WORDS),
      47  	DEF_HLPPATH(_PATH_WORDS_ALT),
      48  	DEF_HLPPATH(_PATH_FILESYSTEMS),
      49  	DEF_HLPPATH(_PATH_PROC_SWAPS),
      50  	DEF_HLPPATH(_PATH_PROC_FILESYSTEMS),
      51  	DEF_HLPPATH(_PATH_MOUNTED),
      52  	DEF_HLPPATH(_PATH_MNTTAB),
      53  	DEF_HLPPATH(_PATH_DEV_BYLABEL),
      54  	DEF_HLPPATH(_PATH_DEV_BYUUID),
      55  	{ NULL, NULL }
      56  };
      57  
      58  int
      59  main(int argc, char **argv)
      60  {
      61  	struct hlpPath *p;
      62  
      63  	if (argc == 1) {
      64  		for (p = paths; p->name; p++)
      65  			printf("%20s %s\n", p->name, p->path);
      66  		exit(EXIT_SUCCESS);
      67  	} else {
      68  		if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) {
      69  			printf("%s <option>\n", argv[0]);
      70  			fputs("options:\n", stdout);
      71  			for (p = paths; p->name; p++)
      72  				printf("\t%s\n", p->name);
      73  			exit(EXIT_SUCCESS);
      74  		}
      75  
      76  		for (p = paths; p->name; p++) {
      77  			if (strcmp(p->name, argv[1]) == 0) {
      78  				printf("%s\n", p->path);
      79  				exit(EXIT_SUCCESS);
      80  			}
      81  		}
      82  	}
      83  
      84  	exit(EXIT_FAILURE);
      85  }
      86