endslash.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. /*
  24. * COMPONENT_NAME: austext
  25. *
  26. * FUNCTIONS: ensure_end_slash
  27. *
  28. * ORIGINS: 27
  29. *
  30. *
  31. * (C) COPYRIGHT International Business Machines Corp. 1995,1996
  32. * All Rights Reserved
  33. * Licensed Materials - Property of IBM
  34. * US Government Users Restricted Rights - Use, duplication or
  35. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  36. */
  37. /************** ENDSLASH.C ****************
  38. * $XConsortium: endslash.c /main/4 1996/05/07 13:33:42 drk $
  39. * If passed path name string does not end in a slash, adds a slash.
  40. * There MUST BE ROOM for the extra slash in the passed string buffer!
  41. * Does nothing if passed pathstr is completely empty
  42. * to prevent a presumed 'root path' for files in curr work dir.
  43. * Returns ptr to zero byte at end of string.
  44. *
  45. * $Log$
  46. * Revision 2.2 1995/10/26 15:23:51 miker
  47. * Added prolog.
  48. *
  49. * Revision 2.1 1995/09/22 19:52:53 miker
  50. * Freeze DtSearch 0.1, AusText 2.1.8
  51. *
  52. * Revision 1.1 1995/07/18 22:41:43 miker
  53. * Initial release as separate module.
  54. */
  55. #include <string.h>
  56. char *ensure_end_slash (char *pathstr)
  57. {
  58. char *cptr = pathstr + strlen(pathstr) - 1;
  59. if (*pathstr == 0)
  60. return pathstr;
  61. if (*cptr++ != '/') {
  62. *cptr++ = '/';
  63. *cptr = 0;
  64. }
  65. return cptr;
  66. }