libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

mhd_has_in_name.h (2119B)


      1 /*
      2   This file is part of libmicrohttpd
      3   Copyright (C) 2016-2021 Karlson2k (Evgeny Grin)
      4 
      5   This library is free software; you can redistribute it and/or
      6   modify it under the terms of the GNU Lesser General Public
      7   License as published by the Free Software Foundation; either
      8   version 2.1 of the License, or (at your option) any later version.
      9 
     10   This library is distributed in the hope that it will be useful,
     11   but WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13   Lesser General Public License for more details.
     14 
     15   You should have received a copy of the GNU Lesser General Public
     16   License along with this library; if not, write to the Free Software
     17   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
     18 */
     19 
     20 /**
     21  * @file testcurl/mhd_has_in_name.h
     22  * @brief Static functions and macros helpers for testsuite.
     23  * @author Karlson2k (Evgeny Grin)
     24  */
     25 
     26 #include <string.h>
     27 
     28 /**
     29  * Check whether program name contains specific @a marker string.
     30  * Only last component in pathname is checked for marker presence,
     31  * all leading directories names (if any) are ignored. Directories
     32  * separators are handled correctly on both non-W32 and W32
     33  * platforms.
     34  * @param prog_name program name, may include path
     35  * @param marker    marker to look for.
     36  * @return zero if any parameter is NULL or empty string or
     37  *         @a prog_name ends with slash or @a marker is not found in
     38  *         program name, non-zero if @a maker is found in program
     39  *         name.
     40  */
     41 static int
     42 has_in_name (const char *prog_name, const char *marker)
     43 {
     44   size_t name_pos;
     45   size_t pos;
     46 
     47   if (! prog_name || ! marker || ! prog_name[0] || ! marker[0])
     48     return 0;
     49 
     50   pos = 0;
     51   name_pos = 0;
     52   while (prog_name[pos])
     53   {
     54     if ('/' == prog_name[pos])
     55       name_pos = pos + 1;
     56 #if defined(_WIN32) || defined(__CYGWIN__)
     57     else if ('\\' == prog_name[pos])
     58       name_pos = pos + 1;
     59 #endif /* _WIN32 || __CYGWIN__ */
     60     pos++;
     61   }
     62   if (name_pos == pos)
     63     return 0;
     64   return strstr (prog_name + name_pos, marker) != (char *) 0;
     65 }