Movatterモバイル変換


[0]ホーム

URL:


D Logo
Menu
Search

Library Reference

version 2.112.0

overview

Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.Requires a signed-in GitHub account. This works well for small changes.If you'd like to make larger changes you may want to consider usinga local clone.

dmd.common.file

File utilities.
Functions and objects dedicated to file I/O and management. TODO: Move here artifacts from places such as root/ so both the frontend and the backend have access to them.
Authors:
Walter Bright,https://www.digitalmars.com
License:
Boost License 1.0

Sourcecommon/file.d

Documentationhttps://dlang.org/phobos/dmd_common_file.html

Coveragehttps://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/common/file.d

structFileMapping(Datum);
Encapsulated management of a memory-mapped file.
Parameters:
Datumthe mapped data type: Use a POD of size 1 for read/write mappingand aconst version thereof for read-only mapping. Other primitive typesshould work, but have not been yet tested.
this(const char*filename);
Openfilename and map it in memory. IfDatum isconst, opens for read-only and maps the content in memory; no error is issued if the file does not exist. This makes it easy to treat a non-existing file as empty.
IfDatum is mutable, opens for read/write (creates file if it does not exist) and fails fatally on any error.
Due to quirks inmmap, if the file is empty,handle is valid butdata isnull. This state is valid and accounted for.
Parameters:
char*filenamethe name of the file to be mapped in memory
voidclose();
Frees resources associated with this mapping. However, it does not deallocate the name. Reinitializesthis as a fresh object that can be reused.
booldiscard();
Deletes the underlying file and frees all resources associated. Reinitializesthis as a fresh object that can be reused.
This function does not abort if the file cannot be deleted, but does print a message onstderr and returnsfalse to the caller. The underlying rationale is to give the caller the option to continue execution if deleting the file is not important.
Returns:
true iff the file was successfully deleted. If the file was not deleted, prints a message tostderr and returnsfalse.
pure nothrow @nogc boolactive() const;
Queries whetherthis is currently associated with a file.
Returns:
true iff there is an active mapping.
pure nothrow @nogc @safe size_tlength() const;
Queries the length of the file associated with this mapping. If not active, returns 0.
Returns:
the length of the file, or 0 if no file associated.
pure nothrow @nogc @safe autoopSlice();
Get a slice to the contents of the entire file.
Returns:
the contents of the file. If not active, returns thenull slice.
pure voidresize(size_tsize);
Resizes the file and mapping to the specifiedsize.
Parameters:
size_tsizenew length requested
boolmoveToFile(const char*filename);
Unconditionally and destructively moves the underlying file tofilename. If the operation succeeds, returns true. Upon failure, prints a message tostderr and returnsfalse. In all cases it closes the underlying file.
Parameters:
char*filenamezero-terminated name of the file to move to.
Returns:
true iff the operation was successful.
static nothrow boolwriteFile(const(char)*name, const void[]data);
Write a file, returningtrue on success.
nothrow booltouchFile(const char*namez);
Touch a file to current date
nothrow boolfindFiles(const char*dir_path, const char[][]exts, boolrecurse, void delegate(const(char)[]) nothrowfilenameSink);
Recursively search all the directories and files under dir_path for files that match one of the extensions in exts[]. Pass the matches to sink.
Parameters:
char*dir_pathroot of directories to search
char[][]extsarray of filename extensions to match
boolrecursego into subdirectories
void delegate(const(char)[]) nothrowfilenameSinkaccepts the resulting matches
Returns:
true for failed to open the directory
Copyright © 1999-2026 by theD Language Foundation | Page generated byDdoc on Fri Feb 20 17:56:13 2026

[8]ページ先頭

©2009-2026 Movatter.jp