mirror of
https://github.com/dlang/phobos.git
synced 2025-05-04 17:11:26 +03:00
Merge OSX and Posix implementations of browse
They are identical except their usage of open vs. xdg-open
This commit is contained in:
parent
08927149cc
commit
d186363752
1 changed files with 11 additions and 38 deletions
|
@ -4139,42 +4139,6 @@ version (Windows)
|
||||||
ShellExecuteW(null, "open", url.tempCStringW(), null, null, SW_SHOWNORMAL);
|
ShellExecuteW(null, "open", url.tempCStringW(), null, null, SW_SHOWNORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else version (OSX)
|
|
||||||
{
|
|
||||||
import core.stdc.stdio;
|
|
||||||
import core.stdc.string;
|
|
||||||
import core.sys.posix.unistd;
|
|
||||||
|
|
||||||
void browse(scope const(char)[] url) nothrow @nogc
|
|
||||||
{
|
|
||||||
const(char)*[5] args;
|
|
||||||
|
|
||||||
auto curl = url.tempCString();
|
|
||||||
const(char)* browser = core.stdc.stdlib.getenv("BROWSER");
|
|
||||||
if (browser)
|
|
||||||
{ browser = strdup(browser);
|
|
||||||
args[0] = browser;
|
|
||||||
args[1] = curl;
|
|
||||||
args[2] = null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
args[0] = "open".ptr;
|
|
||||||
args[1] = curl;
|
|
||||||
args[2] = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto childpid = core.sys.posix.unistd.fork();
|
|
||||||
if (childpid == 0)
|
|
||||||
{
|
|
||||||
core.sys.posix.unistd.execvp(args[0], cast(char**) args.ptr);
|
|
||||||
perror(args[0]); // failed to execute
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (browser)
|
|
||||||
free(cast(void*) browser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else version (Posix)
|
else version (Posix)
|
||||||
{
|
{
|
||||||
import core.stdc.stdio;
|
import core.stdc.stdio;
|
||||||
|
@ -4191,8 +4155,17 @@ else version (Posix)
|
||||||
args[0] = browser;
|
args[0] = browser;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
version (OSX)
|
||||||
|
{
|
||||||
|
args[0] = "open".ptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
//args[0] = "x-www-browser".ptr; // doesn't work on some systems
|
//args[0] = "x-www-browser".ptr; // doesn't work on some systems
|
||||||
args[0] = "xdg-open".ptr;
|
args[0] = "xdg-open".ptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const buffer = url.tempCString(); // Retain buffer until end of scope
|
const buffer = url.tempCString(); // Retain buffer until end of scope
|
||||||
args[1] = buffer;
|
args[1] = buffer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue