]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/d/dmd/utils.c
e3ea8c19e50432196ed60cfa77fc001dd6099698
2 /* Compiler implementation of the D programming language
3 * Copyright (C) 1999-2018 by The D Language Foundation, All Rights Reserved
4 * written by Walter Bright
5 * http://www.digitalmars.com
6 * Distributed under the Boost Software License, Version 1.0.
7 * http://www.boost.org/LICENSE_1_0.txt
13 #include "root/file.h"
14 #include "root/filename.h"
15 #include "root/outbuffer.h"
18 * Normalize path by turning forward slashes into backslashes
21 * src = Source path, using unix-style ('/') path separators
24 * A newly-allocated string with '/' turned into backslashes
26 const char * toWinPath(const char *src
)
31 char *result
= strdup(src
);
43 * Reads a file, terminate the program on error
46 * loc = The line number information from where the call originates
47 * f = a `ddmd.root.file.File` handle to read
49 void readFile(Loc loc
, File
*f
)
53 error(loc
, "Error reading file '%s'", f
->name
->toChars());
59 * Writes a file, terminate the program on error
62 * loc = The line number information from where the call originates
63 * f = a `ddmd.root.file.File` handle to write
65 void writeFile(Loc loc
, File
*f
)
69 error(loc
, "Error writing file '%s'", f
->name
->toChars());
75 * Ensure the root path (the path minus the name) of the provided path
76 * exists, and terminate the process if it doesn't.
79 * loc = The line number information from where the call originates
80 * name = a path to check (the name is stripped)
82 void ensurePathToNameExists(Loc loc
, const char *name
)
84 const char *pt
= FileName::path(name
);
87 if (FileName::ensurePathExists(pt
))
89 error(loc
, "cannot create directory %s", pt
);
97 * Takes a path, and escapes '(', ')' and backslashes
100 * buf = Buffer to write the escaped path to
101 * fname = Path to escape
103 void escapePath(OutBuffer
*buf
, const char *fname
)
114 buf
->writeByte('\\');
117 buf
->writeByte(*fname
);