src/FileSystem.cpp
changeset 251 ca99a81745fe
child 255 b3cf7e052ddf
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/FileSystem.cpp	Tue Jan 01 15:34:07 2013 -0800
     1.3 @@ -0,0 +1,41 @@
     1.4 +/*
     1.5 + * Copyright (C) 2012 David Anderson
     1.6 + *
     1.7 + * This file is part of SourcePawn.
     1.8 + *
     1.9 + * SourcePawn is free software: you can redistribute it and/or modify it under
    1.10 + * the terms of the GNU General Public License as published by the Free
    1.11 + * Software Foundation, either version 3 of the License, or (at your option)
    1.12 + * any later version.
    1.13 + * 
    1.14 + * SourcePawn is distributed in the hope that it will be useful, but WITHOUT ANY
    1.15 + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.16 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License along with
    1.19 + * SourcePawn. If not, see http://www.gnu.org/licenses/.
    1.20 + */
    1.21 +#include <string.h>
    1.22 +#include "Zone.h"
    1.23 +#include "FileSystem.h"
    1.24 +
    1.25 +bool
    1.26 +ke::JoinPaths(Zone *zone, AutoFree<char> &result, const char *base, const char *name)
    1.27 +{
    1.28 +    const char *sep = OS::PathSeparator();
    1.29 +
    1.30 +    size_t baselen = strlen(base);
    1.31 +    size_t namelen = strlen(name);
    1.32 +    size_t seplen = strlen(sep);
    1.33 +
    1.34 +    char *ptr = (char *)zone->malloc(baselen + seplen + namelen + 1);
    1.35 +    if (!ptr)
    1.36 +        return false;
    1.37 +
    1.38 +    strcpy(ptr, base);
    1.39 +    strcpy(ptr + baselen, sep);
    1.40 +    strcpy(ptr + baselen + seplen, name);
    1.41 +
    1.42 +    result = ptr;
    1.43 +    return true;
    1.44 +}