Blame lib/globfree.c

Packit 1ac44c
/* Frees the dynamically allocated storage from an earlier call to glob.
Packit 1ac44c
   Copyright (C) 2017-2018 Free Software Foundation, Inc.
Packit 1ac44c
   This file is part of the GNU C Library.
Packit 1ac44c
Packit 1ac44c
   The GNU C Library is free software; you can redistribute it and/or
Packit 1ac44c
   modify it under the terms of the GNU General Public
Packit 1ac44c
   License as published by the Free Software Foundation; either
Packit 1ac44c
   version 3 of the License, or (at your option) any later version.
Packit 1ac44c
Packit 1ac44c
   The GNU C Library is distributed in the hope that it will be useful,
Packit 1ac44c
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 1ac44c
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 1ac44c
   General Public License for more details.
Packit 1ac44c
Packit 1ac44c
   You should have received a copy of the GNU General Public
Packit 1ac44c
   License along with the GNU C Library; if not, see
Packit 1ac44c
   <https://www.gnu.org/licenses/>.  */
Packit 1ac44c
Packit 1ac44c
#ifndef _LIBC
Packit 1ac44c
# include <config.h>
Packit 1ac44c
#endif
Packit 1ac44c
Packit 1ac44c
#include <glob.h>
Packit 1ac44c
#include <stdlib.h>
Packit 1ac44c
Packit 1ac44c
/* Free storage allocated in PGLOB by a previous `glob' call.  */
Packit 1ac44c
void
Packit 1ac44c
globfree (glob_t *pglob)
Packit 1ac44c
{
Packit 1ac44c
  if (pglob->gl_pathv != NULL)
Packit 1ac44c
    {
Packit 1ac44c
      size_t i;
Packit 1ac44c
      for (i = 0; i < pglob->gl_pathc; ++i)
Packit 1ac44c
        free (pglob->gl_pathv[pglob->gl_offs + i]);
Packit 1ac44c
      free (pglob->gl_pathv);
Packit 1ac44c
      pglob->gl_pathv = NULL;
Packit 1ac44c
    }
Packit 1ac44c
}
Packit 1ac44c
#ifndef globfree
Packit 1ac44c
libc_hidden_def (globfree)
Packit 1ac44c
#endif