mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 05:30:33 +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);
|
||||
}
|
||||
}
|
||||
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)
|
||||
{
|
||||
import core.stdc.stdio;
|
||||
|
@ -4191,8 +4155,17 @@ else version (Posix)
|
|||
args[0] = browser;
|
||||
}
|
||||
else
|
||||
//args[0] = "x-www-browser".ptr; // doesn't work on some systems
|
||||
args[0] = "xdg-open".ptr;
|
||||
{
|
||||
version (OSX)
|
||||
{
|
||||
args[0] = "open".ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
//args[0] = "x-www-browser".ptr; // doesn't work on some systems
|
||||
args[0] = "xdg-open".ptr;
|
||||
}
|
||||
}
|
||||
|
||||
const buffer = url.tempCString(); // Retain buffer until end of scope
|
||||
args[1] = buffer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue