Files
c3c/utils/file_utils.c
Christoffer Lerno 88b2dc547e Project setup
2019-07-13 22:46:39 +02:00

20 lines
496 B
C

// Copyright (c) 2019 Christoffer Lerno. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
#include "file_utils.h"
#include <stdio.h>
#include <stdlib.h>
const char* expand_path(const char* path)
{
if (path[0] == '~' && path[1] == '/')
{
// Ignore leak.
char *ret = NULL;
char *home = getenv("HOME");
if (!home || asprintf(&ret, "%s%s", home, &path[1]) == -1) return &path[2];
return ret;
}
return path;
}