"Fossies" - the Fresh Open Source Software Archive

Member "tin-2.4.1/src/joinpath.c" (12 Oct 2016, 2435 Bytes) of archive /linux/misc/tin-2.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "joinpath.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.4.0_vs_2.4.1.

    1 /*
    2  *  Project   : tin - a Usenet reader
    3  *  Module    : joinpath.c
    4  *  Author    : Thomas Dickey <dickey@invisible-island.net>
    5  *  Created   : 1997-01-10
    6  *  Updated   : 2008-12-04
    7  *  Notes     :
    8  *
    9  * Copyright (c) 1997-2017 Thomas Dickey <dickey@invisible-island.net>
   10  * All rights reserved.
   11  *
   12  * Redistribution and use in source and binary forms, with or without
   13  * modification, are permitted provided that the following conditions
   14  * are met:
   15  * 1. Redistributions of source code must retain the above copyright
   16  *    notice, this list of conditions and the following disclaimer.
   17  * 2. Redistributions in binary form must reproduce the above copyright
   18  *    notice, this list of conditions and the following disclaimer in the
   19  *    documentation and/or other materials provided with the distribution.
   20  * 3. The name of the author may not be used to endorse or promote
   21  *    products derived from this software without specific prior written
   22  *    permission.
   23  *
   24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
   25  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
   28  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
   30  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   32  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   33  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   34  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   35  */
   36 
   37 
   38 #ifndef TIN_H
   39 #   include "tin.h"
   40 #endif /* !TIN_H */
   41 
   42 /*
   43  * Concatenate dir+file, ensuring that we don't introduce extra '/', since some
   44  * systems (e.g., Apollo) use "//" for special purposes.
   45  */
   46 void
   47 joinpath(
   48     char *result,
   49     size_t result_size,
   50     const char *dir,
   51     const char *file)
   52 {
   53     size_t result_len;
   54 
   55     (void) strncpy(result, dir, result_size - 1);
   56     result[result_size - 1] = '\0';
   57     result_len = strlen(result);
   58     if ((result_len < (result_size - 1)) && (result[0] == '\0' || result[strlen(result) - 1] != '/')) {
   59         (void) strcat(result, "/");
   60         result_len++;
   61     }
   62     if (result_len < (result_size - 1)) {
   63         (void) strncat(result, BlankIfNull(file), result_size - result_len - 1);
   64         result[result_size - 1] = '\0';
   65     }
   66 }