{"action":"created","comment":{"url":"https://api.github.com/repos/dlang/phobos/pulls/comments/179911238","pull_request_review_id":110249543,"id":179911238,"diff_hunk":"@@ -868,20 +849,202 @@ version(Windows) private void writeImpl(const(char)[] name, const(FSChar)* namez\n         h = CreateFileW(namez, defaults);\n         cenforce(h != INVALID_HANDLE_VALUE, name, namez);\n     }\n+    writeToOpenFile(h, buffer, name, namez);\n+}\n+\n+private void writeToOpenFile(FD)(FD fd, const void[] buffer, const(char)[] name,\n+                                 const(FSChar)* namez) @trusted\n+{\n     immutable size = buffer.length;\n     size_t sum, cnt = void;\n-    DWORD numwritten = void;\n+\n     while (sum != size)\n     {\n-        cnt = (size - sum < 2^^30) ? (size - sum) : 2^^30;\n-        WriteFile(h, buffer.ptr + sum, cast(uint) cnt, &numwritten, null);\n-        if (numwritten != cnt)\n+        cnt = size - sum < 2^^30 ? size - sum : 2^^30;\n+\n+        version(Posix)\n+            immutable numWritten = core.sys.posix.unistd.write(fd, buffer.ptr + sum, cnt);\n+        else version(Windows)\n+        {\n+            DWORD numWritten = void;\n+            WriteFile(fd, buffer.ptr + sum, cast(uint) cnt, &numWritten, null);\n+        }\n+        else\n+            static assert(0, \"Unsupported OS\");\n+\n+        if (numWritten != cnt)\n             break;\n-        sum += numwritten;\n+        sum += numWritten;\n     }\n-    cenforce(sum == size && CloseHandle(h), name, namez);\n+\n+    version(Posix)\n+        cenforce(sum == size && core.sys.posix.unistd.close(fd) == 0, name, namez);\n+    else version(Windows)\n+        cenforce(sum == size && CloseHandle(fd), name, namez);\n+    else\n+        static assert(0, \"Unsupported OS\");\n }\n \n+\n+/++\n+    Creates a file with a random name in $(LREF tempDir) and returns the name\n+    of the file. If data is passed in, then the file is written with that data;\n+    otherwise, it's empty.\n+\n+    The idea is that this creates a temporary file for testing or whatever\n+    other purpose a temporary file might be needed for. However, it will only\n+    be deleted if it's explicitly deleted or if the OS decides to delete it as\n+    some OSes do with files in temp directories on startup or shutdown. So,\n+    unlike $(REF File.tmpfile, std, stdio), the file has a name, and it can have\n+    all of the things done to it that one might typically do with a file\n+    (including reopening it after closing it).\n+\n+    The file is created with R/W permissions. On POSIX systems, the permissions\n+    are restricted to the current user, though the effective permissions are\n+    modified by the process' umask in the usual way.","path":"std/file.d","position":108,"original_position":108,"commit_id":"a4b45bbc46f487e0e1a175fcbe2134e826f098b9","original_commit_id":"a4b45bbc46f487e0e1a175fcbe2134e826f098b9","user":{"login":"jmdavis","id":579956,"avatar_url":"https://avatars1.githubusercontent.com/u/579956?v=4","gravatar_id":"","url":"https://api.github.com/users/jmdavis","html_url":"https://github.com/jmdavis","followers_url":"https://api.github.com/users/jmdavis/followers","following_url":"https://api.github.com/users/jmdavis/following{/other_user}","gists_url":"https://api.github.com/users/jmdavis/gists{/gist_id}","starred_url":"https://api.github.com/users/jmdavis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmdavis/subscriptions","organizations_url":"https://api.github.com/users/jmdavis/orgs","repos_url":"https://api.github.com/users/jmdavis/repos","events_url":"https://api.github.com/users/jmdavis/events{/privacy}","received_events_url":"https://api.github.com/users/jmdavis/received_events","type":"User","site_admin":false},"body":"Important? I don't think so. We don't provide that ability with `write`, and that does start getting a bit system-specific to implement. It might be a reasonable enhancement, but if we did something like that, then we'd need to do the same with other functions like `write`. So, if we want to do that, I think that it should be left to a separate PR.","created_at":"2018-04-07T07:53:21Z","updated_at":"2018-04-07T07:53:22Z","html_url":"https://github.com/dlang/phobos/pull/5788#discussion_r179911238","pull_request_url":"https://api.github.com/repos/dlang/phobos/pulls/5788","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/dlang/phobos/pulls/comments/179911238"},"html":{"href":"https://github.com/dlang/phobos/pull/5788#discussion_r179911238"},"pull_request":{"href":"https://api.github.com/repos/dlang/phobos/pulls/5788"}},"in_reply_to_id":179906286},"pull_request":{"url":"https://api.github.com/repos/dlang/phobos/pulls/5788","id":147177401,"html_url":"https://github.com/dlang/phobos/pull/5788","diff_url":"https://github.com/dlang/phobos/pull/5788.diff","patch_url":"https://github.com/dlang/phobos/pull/5788.patch","issue_url":"https://api.github.com/repos/dlang/phobos/issues/5788","number":5788,"state":"open","locked":false,"title":"Issue 17912: Add function for creating a temporary file.","user":{"login":"jmdavis","id":579956,"avatar_url":"https://avatars1.githubusercontent.com/u/579956?v=4","gravatar_id":"","url":"https://api.github.com/users/jmdavis","html_url":"https://github.com/jmdavis","followers_url":"https://api.github.com/users/jmdavis/followers","following_url":"https://api.github.com/users/jmdavis/following{/other_user}","gists_url":"https://api.github.com/users/jmdavis/gists{/gist_id}","starred_url":"https://api.github.com/users/jmdavis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmdavis/subscriptions","organizations_url":"https://api.github.com/users/jmdavis/orgs","repos_url":"https://api.github.com/users/jmdavis/repos","events_url":"https://api.github.com/users/jmdavis/events{/privacy}","received_events_url":"https://api.github.com/users/jmdavis/received_events","type":"User","site_admin":false},"body":"This adds std.file.createTempFile, which creates a temporary file with a\r\nrandom name (optionally with a specified prefix and/or suffix). By\r\ndefault, the file is empty, but if data is passed to createTempFile,\r\nthen the file is populated with that data just like it would have been\r\nwith std.file.write. The name of the file that was created is returned.\r\nSo, essentially, createTempFile is like write except that it generates\r\nthe file name for you and returns it.\r\n\r\nPreviously, we added scratchFile to std.stdio, which was like\r\ncreateTempFile except that it gave you an open File object, but it was\r\nscrapped, because the dependencies that it added to std.stdio made\r\n\"hello world\" bigger. See:\r\nhttps://issues.dlang.org/show_bug.cgi?id=14599\r\n\r\nJust like scratchFile did, createTempFile ensures that a filename is\r\nselected which did not exist previously so that the file can't be\r\nhijacked with different permissions by someone creating a file with the\r\nsame name beforehand (the randomness of the name should make that\r\neffectively impossible, but the way that createTempFile opens the file\r\nguarantees it).\r\n\r\nThese changes also consolidate some of write's implementation across\r\nOSes, since the writing portion of writeImpl was esentially identical\r\nacross OSes but needlessly duplicated. That consolidated functionality\r\nis then also used by createTempFile.\r\n\r\nUnfortunately, I don't currently have a Windows setup that I can test this with, so depending on what happens with the autotester, I may need to make a revision or two to get it to pass on Windows. I might get lucky though.","created_at":"2017-10-17T23:26:34Z","updated_at":"2018-04-07T07:53:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"29f0ea063b6e588d70ec16fe21083ee6e517f13e","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":416188433,"url":"https://api.github.com/repos/dlang/phobos/labels/Enhancement","name":"Enhancement","color":"5319e7","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/dlang/phobos/pulls/5788/commits","review_comments_url":"https://api.github.com/repos/dlang/phobos/pulls/5788/comments","review_comment_url":"https://api.github.com/repos/dlang/phobos/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dlang/phobos/issues/5788/comments","statuses_url":"https://api.github.com/repos/dlang/phobos/statuses/a4b45bbc46f487e0e1a175fcbe2134e826f098b9","head":{"label":"jmdavis:tempFile2","ref":"tempFile2","sha":"a4b45bbc46f487e0e1a175fcbe2134e826f098b9","user":{"login":"jmdavis","id":579956,"avatar_url":"https://avatars1.githubusercontent.com/u/579956?v=4","gravatar_id":"","url":"https://api.github.com/users/jmdavis","html_url":"https://github.com/jmdavis","followers_url":"https://api.github.com/users/jmdavis/followers","following_url":"https://api.github.com/users/jmdavis/following{/other_user}","gists_url":"https://api.github.com/users/jmdavis/gists{/gist_id}","starred_url":"https://api.github.com/users/jmdavis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmdavis/subscriptions","organizations_url":"https://api.github.com/users/jmdavis/orgs","repos_url":"https://api.github.com/users/jmdavis/repos","events_url":"https://api.github.com/users/jmdavis/events{/privacy}","received_events_url":"https://api.github.com/users/jmdavis/received_events","type":"User","site_admin":false},"repo":{"id":1344978,"name":"phobos","full_name":"jmdavis/phobos","owner":{"login":"jmdavis","id":579956,"avatar_url":"https://avatars1.githubusercontent.com/u/579956?v=4","gravatar_id":"","url":"https://api.github.com/users/jmdavis","html_url":"https://github.com/jmdavis","followers_url":"https://api.github.com/users/jmdavis/followers","following_url":"https://api.github.com/users/jmdavis/following{/other_user}","gists_url":"https://api.github.com/users/jmdavis/gists{/gist_id}","starred_url":"https://api.github.com/users/jmdavis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jmdavis/subscriptions","organizations_url":"https://api.github.com/users/jmdavis/orgs","repos_url":"https://api.github.com/users/jmdavis/repos","events_url":"https://api.github.com/users/jmdavis/events{/privacy}","received_events_url":"https://api.github.com/users/jmdavis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jmdavis/phobos","description":"Runtime library for the D programming language","fork":true,"url":"https://api.github.com/repos/jmdavis/phobos","forks_url":"https://api.github.com/repos/jmdavis/phobos/forks","keys_url":"https://api.github.com/repos/jmdavis/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jmdavis/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jmdavis/phobos/teams","hooks_url":"https://api.github.com/repos/jmdavis/phobos/hooks","issue_events_url":"https://api.github.com/repos/jmdavis/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/jmdavis/phobos/events","assignees_url":"https://api.github.com/repos/jmdavis/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/jmdavis/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/jmdavis/phobos/tags","blobs_url":"https://api.github.com/repos/jmdavis/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jmdavis/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jmdavis/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/jmdavis/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jmdavis/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/jmdavis/phobos/languages","stargazers_url":"https://api.github.com/repos/jmdavis/phobos/stargazers","contributors_url":"https://api.github.com/repos/jmdavis/phobos/contributors","subscribers_url":"https://api.github.com/repos/jmdavis/phobos/subscribers","subscription_url":"https://api.github.com/repos/jmdavis/phobos/subscription","commits_url":"https://api.github.com/repos/jmdavis/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/jmdavis/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/jmdavis/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/jmdavis/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/jmdavis/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/jmdavis/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jmdavis/phobos/merges","archive_url":"https://api.github.com/repos/jmdavis/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jmdavis/phobos/downloads","issues_url":"https://api.github.com/repos/jmdavis/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/jmdavis/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/jmdavis/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/jmdavis/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jmdavis/phobos/labels{/name}","releases_url":"https://api.github.com/repos/jmdavis/phobos/releases{/id}","deployments_url":"https://api.github.com/repos/jmdavis/phobos/deployments","created_at":"2011-02-09T04:09:04Z","updated_at":"2018-03-31T05:58:04Z","pushed_at":"2018-03-31T05:57:58Z","git_url":"git://github.com/jmdavis/phobos.git","ssh_url":"git@github.com:jmdavis/phobos.git","clone_url":"https://github.com/jmdavis/phobos.git","svn_url":"https://github.com/jmdavis/phobos","homepage":"d-programming-language.org","size":46953,"stargazers_count":2,"watchers_count":2,"language":"D","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"bsl-1.0","name":"Boost Software License 1.0","spdx_id":"BSL-1.0","url":"https://api.github.com/licenses/bsl-1.0"},"forks":1,"open_issues":0,"watchers":2,"default_branch":"master"}},"base":{"label":"dlang:master","ref":"master","sha":"f55a6a797d77200f3c1646708e13a8cb8a3ba5f1","user":{"login":"dlang","id":565913,"avatar_url":"https://avatars3.githubusercontent.com/u/565913?v=4","gravatar_id":"","url":"https://api.github.com/users/dlang","html_url":"https://github.com/dlang","followers_url":"https://api.github.com/users/dlang/followers","following_url":"https://api.github.com/users/dlang/following{/other_user}","gists_url":"https://api.github.com/users/dlang/gists{/gist_id}","starred_url":"https://api.github.com/users/dlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlang/subscriptions","organizations_url":"https://api.github.com/users/dlang/orgs","repos_url":"https://api.github.com/users/dlang/repos","events_url":"https://api.github.com/users/dlang/events{/privacy}","received_events_url":"https://api.github.com/users/dlang/received_events","type":"Organization","site_admin":false},"repo":{"id":1257084,"name":"phobos","full_name":"dlang/phobos","owner":{"login":"dlang","id":565913,"avatar_url":"https://avatars3.githubusercontent.com/u/565913?v=4","gravatar_id":"","url":"https://api.github.com/users/dlang","html_url":"https://github.com/dlang","followers_url":"https://api.github.com/users/dlang/followers","following_url":"https://api.github.com/users/dlang/following{/other_user}","gists_url":"https://api.github.com/users/dlang/gists{/gist_id}","starred_url":"https://api.github.com/users/dlang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlang/subscriptions","organizations_url":"https://api.github.com/users/dlang/orgs","repos_url":"https://api.github.com/users/dlang/repos","events_url":"https://api.github.com/users/dlang/events{/privacy}","received_events_url":"https://api.github.com/users/dlang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dlang/phobos","description":"The standard library of the D programming language","fork":false,"url":"https://api.github.com/repos/dlang/phobos","forks_url":"https://api.github.com/repos/dlang/phobos/forks","keys_url":"https://api.github.com/repos/dlang/phobos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dlang/phobos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dlang/phobos/teams","hooks_url":"https://api.github.com/repos/dlang/phobos/hooks","issue_events_url":"https://api.github.com/repos/dlang/phobos/issues/events{/number}","events_url":"https://api.github.com/repos/dlang/phobos/events","assignees_url":"https://api.github.com/repos/dlang/phobos/assignees{/user}","branches_url":"https://api.github.com/repos/dlang/phobos/branches{/branch}","tags_url":"https://api.github.com/repos/dlang/phobos/tags","blobs_url":"https://api.github.com/repos/dlang/phobos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dlang/phobos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dlang/phobos/git/refs{/sha}","trees_url":"https://api.github.com/repos/dlang/phobos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dlang/phobos/statuses/{sha}","languages_url":"https://api.github.com/repos/dlang/phobos/languages","stargazers_url":"https://api.github.com/repos/dlang/phobos/stargazers","contributors_url":"https://api.github.com/repos/dlang/phobos/contributors","subscribers_url":"https://api.github.com/repos/dlang/phobos/subscribers","subscription_url":"https://api.github.com/repos/dlang/phobos/subscription","commits_url":"https://api.github.com/repos/dlang/phobos/commits{/sha}","git_commits_url":"https://api.github.com/repos/dlang/phobos/git/commits{/sha}","comments_url":"https://api.github.com/repos/dlang/phobos/comments{/number}","issue_comment_url":"https://api.github.com/repos/dlang/phobos/issues/comments{/number}","contents_url":"https://api.github.com/repos/dlang/phobos/contents/{+path}","compare_url":"https://api.github.com/repos/dlang/phobos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dlang/phobos/merges","archive_url":"https://api.github.com/repos/dlang/phobos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dlang/phobos/downloads","issues_url":"https://api.github.com/repos/dlang/phobos/issues{/number}","pulls_url":"https://api.github.com/repos/dlang/phobos/pulls{/number}","milestones_url":"https://api.github.com/repos/dlang/phobos/milestones{/number}","notifications_url":"https://api.github.com/repos/dlang/phobos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dlang/phobos/labels{/name}","releases_url":"https://api.github.com/repos/dlang/phobos/releases{/id}","deployments_url":"https://api.github.com/repos/dlang/phobos/deployments","created_at":"2011-01-15T07:00:06Z","updated_at":"2018-04-06T22:24:09Z","pushed_at":"2018-04-06T22:55:40Z","git_url":"git://github.com/dlang/phobos.git","ssh_url":"git@github.com:dlang/phobos.git","clone_url":"https://github.com/dlang/phobos.git","svn_url":"https://github.com/dlang/phobos","homepage":"dlang.org/phobos","size":48174,"stargazers_count":870,"watchers_count":870,"language":"D","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":600,"mirror_url":null,"archived":false,"open_issues_count":109,"license":{"key":"bsl-1.0","name":"Boost Software License 1.0","spdx_id":"BSL-1.0","url":"https://api.github.com/licenses/bsl-1.0"},"forks":600,"open_issues":109,"watchers":870,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dlang/phobos/pulls/5788"},"html":{"href":"https://github.com/dlang/phobos/pull/5788"},"issue":{"href":"https://api.github.com/repos/dlang/phobos/issues/5788"},"comments":{"href":"https://api.github.com/repos/dlang/phobos/issues/5788/comments"},"review_comments":{"href":"https://api.github.com/repos/dlang/phobos/pulls/5788/comments"},"review_comment":{"href":"https://api.github.com/repos/dlang/phobos/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dlang/phobos/pulls/5788/commits"},"statuses":{"href":"https://api.github.com/repos/dlang/phobos/statuses/a4b45bbc46f487e0e1a175fcbe2134e826f098b9"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"jmdavis"}}