checkfilename.c.html 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?xml version='1.0' encoding='iso-8859-1'?>
  2. <!doctype html public '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
  3. <html xmlns='http://www.w3c.org/1999/xhtml' lang='en-us'>
  4. <head>
  5. <title>
  6. checkfilename.c
  7. </title>
  8. <meta http-equiv='content-type' content='text/html;iso-8859-1'/>
  9. <meta name='generator' content='motley-tools 1.9.4 13:40:33 Feb 18 2015'/>
  10. <meta name='author' content='cmaier@cmassoc.net'/>
  11. <meta name='robots' content='noindex,nofollow'/>
  12. <link href='toolkit.css' rel='stylesheet' type='text/css'/>
  13. </head>
  14. <body>
  15. <div class='headerlink'>
  16. [<a href='channel.c.html' title=' channel.c '>PREV</a>]
  17. [<a href='toolkit.html' title=' Index '>HOME</a>]
  18. [<a href='checksum32.c.html' title=' checksum32.c '>NEXT</a>]
  19. </div>
  20. <pre>
  21. /*====================================================================*
  22. *
  23. * bool checkfilename (char const * pathname);
  24. *
  25. * files.h
  26. *
  27. * confirm that the filename portion of a pathname string contains
  28. * only letters, digits, periods, underscores and hyphens;
  29. *
  30. * this prevents users from entering an Ethernet address where a
  31. * filename should appear on the command line; Ethernet addresses
  32. * are also valid filenames;
  33. *
  34. * Motley Tools by Charles Maier &lt;cmaier@cmassoc.net&gt;;
  35. * Copyright (c) 2001-2006 by Charles Maier Associates;
  36. * Licensed under the Internet Software Consortium License;
  37. *
  38. *--------------------------------------------------------------------*/
  39. #ifndef CHECKFILENAME_SOURCE
  40. #define CHECKFILENAME_SOURCE
  41. #include &lt;string.h&gt;
  42. #include &lt;ctype.h&gt;
  43. #include &quot;../tools/files.h&quot;
  44. bool checkfilename (char const * pathname)
  45. {
  46. char const * filename = pathname;
  47. while (*pathname)
  48. {
  49. if ((*pathname == '/') || (*pathname == '\\'))
  50. {
  51. filename = pathname + 1;
  52. }
  53. pathname++;
  54. }
  55. while (isalnum (*filename) || (*filename == '.') || (*filename == '_') || (*filename == '-'))
  56. {
  57. filename++;
  58. }
  59. return (*filename == (char) (0));
  60. }
  61. #endif
  62. </pre>
  63. <div class='footerlink'>
  64. [<a href='channel.c.html' title=' channel.c '>PREV</a>]
  65. [<a href='toolkit.html' title=' Index '>HOME</a>]
  66. [<a href='checksum32.c.html' title=' checksum32.c '>NEXT</a>]
  67. </div>
  68. </body>
  69. </html>