Tcl_FindExecutable(3)

🌸 Tcl_FindExecutable β€” bestie, where even IS your binary?? 🌸

ok so this is a page from the Tcl Library Procedures manual, and it's all about the ✨glamorous✨ job of figuring out which actual file on disk is your app. Two procedures live here: Tcl_FindExecutable and Tcl_GetNameOfExecutable. One of them goes hunting, the other one just tells you what the hunt found. it's giving search party energy πŸ”πŸ’–


✨ NAME ✨

Tcl_FindExecutable, Tcl_GetNameOfExecutable β€” identify or return the name of the binary file containing the application 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <tcl.h>

const char *
Tcl_FindExecutable(argv0)

const char *
Tcl_GetNameOfExecutable()

πŸ’… ARGUMENTS πŸ’…

  • char *argv0 (in) β€” the first command-line argument to the program, which gives the application's name. yes bestie, that means argv[0]. the classic. the OG. πŸ‘‘

🌈 DESCRIPTION 🌈

So Tcl_FindExecutable is the main character here: it computes the full path name of the executable file your application was invoked from, and then it saves that path for Tcl's own internal use. it's not just doing it for fun, okay, Tcl actually needs this. πŸ”₯

Why does Tcl need the executable's path name? Several purposes, bestie:

  • on some platforms it's needed for the implementation of the load command
  • it's also what the info nameofexecutable command hands back to you

The result of Tcl_FindExecutable is the full Tcl version with build information, like for example 9.0.0+abcdef...abcdef.gcc-1002. so yeah, that's what comes back. iconic format, no notes. ✨

🧚 On UNIX platforms 🧚

On UNIX, this procedure is typically invoked as the very first thing in the application's main program. it must be passed argv[0] as its argument. and listen β€” it is important not to change the working directory before the invocation. do not be out here cd-ing around before you call this, I'm begging. 😭

Tcl_FindExecutable uses argv0 along with the PATH environment variable to find the application's executable, if possible. and if it fails to find the binary? then future calls to info nameofexecutable will return an empty string. sad girl hours. πŸ’€

πŸ¦‹ On Windows platforms πŸ¦‹

On Windows, this procedure is typically invoked as the very first thing in the application's main program as well. but the argv[0] argument here is used only to indicate whether the executable has a stderr channel (any non-null value) or not (the value null).

So if Tcl_SetPanicProc is never called and no debugger is running, that little detail determines whether the panic message gets sent to stderr or to a standard system dialog. yes fr fr, your whole panic experience depends on it. πŸ™ˆ

πŸ’œ And Tcl_GetNameOfExecutable? πŸ’œ

Tcl_GetNameOfExecutable simply returns a pointer to the internal full path name of the executable file, exactly as computed by Tcl_FindExecutable. this call is the C API equivalent of the info nameofexecutable command. 🫢

It returns NULL if the internal full path name has not been computed, or is unknown. no path, no pointer, that's the rule.

⚠️ heads up bestie: Tcl_FindExecutable can not be used in stub-enabled extensions. that's not a vibe, that's just a fact. periodt. πŸ’…

πŸ”‘ KEYWORDS πŸ”‘

  • binary
  • executable file

that's the whole page, and honestly? she ate. 🌟

this was the Tcl_FindExecutable(3) page from the Tcl Library Procedures manual β€” page version 8.1, dated back in the day, filed under Tcl. mwah, thanks for reading, ily, go call it as the first thing in main okay?? πŸ˜­πŸ’–πŸŽ€

πŸ“¦ where this page comes from