Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/mscorlib/shared/System/IO/FileStream.Unix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,17 @@ private void Init(FileMode mode, FileShare share)
ignoreNotSupported: true); // just a hint.
}

// Jump to the end of the file if opened as Append.
if (_mode == FileMode.Append)
{
// Jump to the end of the file if opened as Append.
_appendStart = SeekCore(_fileHandle, 0, SeekOrigin.End);
}
else if (mode == FileMode.Create || mode == FileMode.Truncate)
{
// Truncate the file now if the file mode requires it. This ensures that the file only will be truncated
// if opened successfully.
CheckFileCall(Interop.Sys.FTruncate(_fileHandle, 0));
}
}

/// <summary>Initializes a stream from an already open file handle (file descriptor).</summary>
Expand All @@ -128,24 +134,18 @@ private static Interop.Sys.OpenFlags PreOpenConfigurationFromOptions(FileMode mo
{
default:
case FileMode.Open: // Open maps to the default behavior for open(...). No flags needed.
case FileMode.Truncate: // We truncate the file after getting the lock
break;

case FileMode.Append: // Append is the same as OpenOrCreate, except that we'll also separately jump to the end later
case FileMode.OpenOrCreate:
case FileMode.Create: // We truncate the file after getting the lock
flags |= Interop.Sys.OpenFlags.O_CREAT;
break;

case FileMode.Create:
flags |= (Interop.Sys.OpenFlags.O_CREAT | Interop.Sys.OpenFlags.O_TRUNC);
break;

case FileMode.CreateNew:
flags |= (Interop.Sys.OpenFlags.O_CREAT | Interop.Sys.OpenFlags.O_EXCL);
break;

case FileMode.Truncate:
flags |= Interop.Sys.OpenFlags.O_TRUNC;
break;
}

// Translate FileAccess. All possible values map cleanly to corresponding values for open.
Expand Down