PageRenderTime 42ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/std/c_path.h

https://gitlab.com/rpdev/csync
C Header | 136 lines | 16 code | 11 blank | 109 comment | 0 complexity | d99e2235a009d407015609927c28b127 MD5 | raw file
  1. /*
  2. * cynapses libc functions
  3. *
  4. * Copyright (c) 2008-2013 by Andreas Schneider <asn@cryptomilk.org>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file c_path.h
  22. *
  23. * @brief Interface of the cynapses libc path functions
  24. *
  25. * @defgroup cynPathInternals cynapses libc path functions
  26. * @ingroup cynLibraryAPI
  27. *
  28. * @{
  29. */
  30. #ifndef _C_PATH_H
  31. #define _C_PATH_H
  32. #include "c_macro.h"
  33. /**
  34. * @brief Parse directory component.
  35. *
  36. * dirname breaks a null-terminated pathname string into a directory component.
  37. * In the usual case, c_dirname() returns the string up to, but not including,
  38. * the final '/'. Trailing '/' characters are not counted as part of the
  39. * pathname. The caller must free the memory.
  40. *
  41. * @param path The path to parse.
  42. *
  43. * @return The dirname of path or NULL if we can't allocate memory. If path
  44. * does not contain a slash, c_dirname() returns the string ".". If
  45. * path is the string "/", it returns the string "/". If path is
  46. * NULL or an empty string, "." is returned.
  47. */
  48. char *c_dirname(const char *path);
  49. /**
  50. * @brief basename - parse filename component.
  51. *
  52. * basename breaks a null-terminated pathname string into a filename component.
  53. * c_basename() returns the component following the final '/'. Trailing '/'
  54. * characters are not counted as part of the pathname.
  55. *
  56. * @param path The path to parse.
  57. *
  58. * @return The filename of path or NULL if we can't allocate memory. If path
  59. * is a the string "/", basename returns the string "/". If path is
  60. * NULL or an empty string, "." is returned.
  61. */
  62. char *c_basename (const char *path);
  63. /**
  64. * @brief Make a temporary filename.
  65. *
  66. * @param template Template to replace. The last six characters of template
  67. * must be XXXXXX and these are replaced with a string that
  68. * makes the filename more or less unique. Since it will be
  69. * modified, template must not be a string constant, but
  70. * should be declared as a character array.
  71. *
  72. * @return 0 on succes, < 0 on error with errno set.
  73. */
  74. int c_tmpname(char *template);
  75. /**
  76. * @brief parse a uri and split it into components.
  77. *
  78. * parse_uri parses an uri in the format
  79. *
  80. * [<scheme>:][//[<user>[:<password>]@]<host>[:<port>]]/[<path>]
  81. *
  82. * into its compoments. If you only want a special component,
  83. * pass NULL for all other components. All components will be allocated if they have
  84. * been found.
  85. *
  86. * @param uri The uri to parse.
  87. * @param scheme String for the scheme component
  88. * @param user String for the username component
  89. * @param passwd String for the password component
  90. * @param host String for the password component
  91. * @param port Integer for the port
  92. * @param path String for the path component with a leading slash.
  93. *
  94. * @return 0 on success, < 0 on error.
  95. */
  96. int c_parse_uri(const char *uri, char **scheme, char **user, char **passwd,
  97. char **host, unsigned int *port, char **path);
  98. /**
  99. * @brief Parts of a path.
  100. *
  101. * @param directory '\0' terminated path including the final '/'
  102. *
  103. * @param filename '\0' terminated string
  104. *
  105. * @param extension '\0' terminated string
  106. *
  107. */
  108. typedef struct
  109. {
  110. char * directory;
  111. char * filename;
  112. char * extension;
  113. } C_PATHINFO;
  114. /**
  115. * @brief Extracting directory, filename and extension from a path.
  116. *
  117. * @param pathSrc The path to parse.
  118. *
  119. * @return Returns a C_PATHINFO structure that should be freed using SAFE_FREE().
  120. */
  121. C_PATHINFO * c_split_path(const char* pathSrc);
  122. /**
  123. * }@
  124. */
  125. #endif /* _C_PATH_H */