isfname.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /*%% (c) Copyright 1993, 1994 Hewlett-Packard Company */
  24. /*%% (c) Copyright 1993, 1994 International Business Machines Corp. */
  25. /*%% (c) Copyright 1993, 1994 Sun Microsystems, Inc. */
  26. /*%% (c) Copyright 1993, 1994 Novell, Inc. */
  27. /*%% $XConsortium: isfname.c /main/3 1995/10/23 11:40:04 rswiston $ */
  28. /*
  29. * Copyright (c) 1988 by Sun Microsystems, Inc.
  30. */
  31. /*
  32. * isfname.c
  33. *
  34. * Description:
  35. * Functions to translate ISAM file name to .rec, .ind, and .var file
  36. * names. Also, several auxiliary functions that deal with path names.
  37. *
  38. */
  39. #include "isam_impl.h"
  40. void _removelast();
  41. char *_lastelement();
  42. /*
  43. * _makedat_isfname(isfname)
  44. *
  45. * Return path to .rec file corresponding to the ISAM file isfname.
  46. * Conversion is done in place.
  47. */
  48. void
  49. _makedat_isfname(char *isfname)
  50. {
  51. /* Append .rec */
  52. (void) strcat(isfname, DAT_SUFFIX);
  53. }
  54. /*
  55. * _makeind_isfname(isfname)
  56. *
  57. * Return path to .ind file corresponding to the ISAM file isfname.
  58. * Conversion is done in place.
  59. */
  60. void
  61. _makeind_isfname(char *isfname)
  62. {
  63. /* Append .ind */
  64. (void) strcat(isfname, IND_SUFFIX);
  65. }
  66. /*
  67. * _makevar_isfname(isfname)
  68. *
  69. * Return path to .var file corresponding to the ISAM file isfname.
  70. * Conversion is done in place.
  71. */
  72. void
  73. _makevar_isfname(char *isfname)
  74. {
  75. /* Append .var */
  76. (void) strcat(isfname, VAR_SUFFIX);
  77. }
  78. /*
  79. * _removelast(path)
  80. *
  81. * Remove last element of path. E.g. /usr/db/part yields /usr/db.
  82. */
  83. void
  84. _removelast(char *path)
  85. {
  86. char *p;
  87. for (p = path + strlen(path); *--p != '/' && p >= path; )
  88. *p = '\0';
  89. }
  90. /*
  91. * _lastelement(path)
  92. *
  93. * Return pointer to the last element in the path.
  94. * E.g.: _lastelement("/usr/temp") returns "temp".
  95. */
  96. char *
  97. _lastelement(char *path)
  98. {
  99. char *p;
  100. p = path + strlen(path);
  101. while (*--p != '/' && p > path)
  102. { ; }
  103. return ((*p == '/') ? (p + 1) : p);
  104. }