Blame src/microhttpd/test_helpers.h

Packit 875988
/*
Packit 875988
  This file is part of libmicrohttpd
Packit 875988
  Copyright (C) 2016 Karlson2k (Evgeny Grin)
Packit 875988
Packit 875988
  This library is free software; you can redistribute it and/or
Packit 875988
  modify it under the terms of the GNU Lesser General Public
Packit 875988
  License as published by the Free Software Foundation; either
Packit 875988
  version 2.1 of the License, or (at your option) any later version.
Packit 875988
Packit 875988
  This library is distributed in the hope that it will be useful,
Packit 875988
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 875988
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 875988
  Lesser General Public License for more details.
Packit 875988
Packit 875988
  You should have received a copy of the GNU Lesser General Public
Packit 875988
  License along with this library; if not, write to the Free Software
Packit 875988
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 875988
*/
Packit 875988
Packit 875988
/**
Packit 875988
 * @file microhttpd/test_helpers.h
Packit 875988
 * @brief Static functions and macros helpers for testsuite.
Packit 875988
 * @author Karlson2k (Evgeny Grin)
Packit 875988
 */
Packit 875988
Packit 875988
#include <string.h>
Packit 875988
Packit 875988
/**
Packit 875988
 * Check whether program name contains specific @a marker string.
Packit 875988
 * Only last component in pathname is checked for marker presence,
Packit 875988
 * all leading directories names (if any) are ignored. Directories
Packit 875988
 * separators are handled correctly on both non-W32 and W32
Packit 875988
 * platforms.
Packit 875988
 * @param prog_name program name, may include path
Packit 875988
 * @param marker    marker to look for.
Packit 875988
 * @return zero if any parameter is NULL or empty string or
Packit 875988
 *         @prog_name ends with slash or @marker is not found in
Packit 875988
 *         program name, non-zero if @maker is found in program
Packit 875988
 *         name.
Packit 875988
 */
Packit 875988
static int
Packit 875988
has_in_name(const char *prog_name, const char *marker)
Packit 875988
{
Packit 875988
  size_t name_pos;
Packit 875988
  size_t pos;
Packit 875988
Packit 875988
  if (!prog_name || !marker || !prog_name[0] || !marker[0])
Packit 875988
    return 0;
Packit 875988
Packit 875988
  pos = 0;
Packit 875988
  name_pos = 0;
Packit 875988
  while (prog_name[pos])
Packit 875988
    {
Packit 875988
      if ('/' == prog_name[pos])
Packit 875988
        name_pos = pos + 1;
Packit 875988
#if defined(_WIN32) || defined(__CYGWIN__)
Packit 875988
      else if ('\\' == prog_name[pos])
Packit 875988
        name_pos = pos + 1;
Packit 875988
#endif /* _WIN32 || __CYGWIN__ */
Packit 875988
      pos++;
Packit 875988
    }
Packit 875988
  if (name_pos == pos)
Packit 875988
    return 0;
Packit 875988
  return strstr(prog_name + name_pos, marker) != (char*)0;
Packit 875988
}
Packit 875988
Packit 875988
/**
Packit 875988
 * Check whether one of strings in array is equal to @a param.
Packit 875988
 * String @a argv[0] is ignored.
Packit 875988
 * @param argc number of strings in @a argv, as passed to main function
Packit 875988
 * @param argv array of strings, as passed to main function
Packit 875988
 * @param param parameter to look for.
Packit 875988
 * @return zero if @a argv is NULL, @a param is NULL or empty string,
Packit 875988
 *         @a argc is less then 2 or @a param is not found in @a argv,
Packit 875988
 *         non-zero if one of strings in @a argv is equal to @a param.
Packit 875988
 */
Packit 875988
static int
Packit 875988
has_param(int argc, char * const argv[], const char * param)
Packit 875988
{
Packit 875988
  int i;
Packit 875988
  if (!argv || !param || !param[0])
Packit 875988
    return 0;
Packit 875988
Packit 875988
  for(i = 1; i < argc; i++)
Packit 875988
    {
Packit 875988
      if(argv[i] && strcmp(argv[i], param) == 0)
Packit 875988
        return !0;
Packit 875988
    }
Packit 875988
Packit 875988
  return 0;
Packit 875988
}