mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
20 lines
496 B
C
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;
|
|
} |