Skip to content

Commit 49d62d3

Browse files
committed
fix: use createTempPath in C grammar
1 parent ccea0bf commit 49d62d3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/grammar-utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,13 @@ temp.track()
1111
const GrammarUtils = {
1212
tempFilesDir: path.join(os.tmpdir(), "atom_script_tempfiles"),
1313

14+
// Public: Create a temporary path
15+
//
16+
// Returns the {String} filepath of the new file
17+
createTempPath(prefix = "", extension = "") {
18+
return temp.path({ dir: this.tempFilesDir, prefix, suffix: extension })
19+
},
20+
1421
// Public: Create a temporary file with the provided code
1522
//
1623
// * `code` A {String} containing some code

lib/grammars/c.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@ const options = "-Wall -include stdio.h"
1111

1212
// TODO add windows support
1313
function CArgs({ filepath }) {
14+
const tempOutFile = GrammarUtils.createTempPath("c-", ".out")
1415
let cmdArgs = ""
1516
switch (os) {
1617
case "darwin":
17-
cmdArgs = `xcrun clang ${options} -fcolor-diagnostics '${filepath}' -o /tmp/c.out && /tmp/c.out`
18+
cmdArgs = `xcrun clang ${options} -fcolor-diagnostics '${filepath}' -o ${tempOutFile} && ${tempOutFile}`
1819
break
1920
case "linux":
20-
cmdArgs = `cc ${options} '${filepath}' -o /tmp/c.out && /tmp/c.out`
21+
cmdArgs = `cc ${options} '${filepath}' -o ${tempOutFile} && ${tempOutFile}`
2122
break
2223
default: {
2324
atom.notifications.addError(`Not support on ${os}`)

0 commit comments

Comments
 (0)