Tcl_SetErrno(3tcl)

πŸ“¦
version 9.0.4 Β· 2 versions
, in ubuntu stonking

πŸ’– Tcl_SetErrno β€” bestie edition πŸ’–

okay so this is a page from the Tcl Library Procedures manual, and it's literally about Tcl_SetErrno, Tcl_GetErrno, Tcl_ErrnoId, Tcl_ErrnoMsg, and Tcl_WinConvertError β€” the whole squad that manipulates errno so you can store and retrieve error codes. no cap. 🫢


✨ NAME ✨

Tcl_SetErrno, Tcl_GetErrno, Tcl_ErrnoId, Tcl_ErrnoMsg, Tcl_WinConvertError β€” manipulate errno to store and retrieve error codes πŸ’…


🌸 SYNOPSIS 🌸

#include <tcl.h>

void
Tcl_SetErrno(errorCode)

int
Tcl_GetErrno()

const char *
Tcl_ErrnoId()

const char *
Tcl_ErrnoMsg(errorCode)

void
Tcl_WinConvertError(winErrorCode)

πŸŽ€ ARGUMENTS πŸŽ€

  • int errorCode (in) β€” a POSIX error code, like ENOENT. yes bestie, that kind of thing πŸ’–
  • DWORD winErrorCode (in) β€” a Windows or Winsock error code, like ERROR_FILE_NOT_FOUND. very Windows-coded of it πŸͺŸ

πŸ‘‘ DESCRIPTION πŸ‘‘

so Tcl_SetErrno and Tcl_GetErrno are your portable hookup to the errno variable β€” that's the thing that records a POSIX error code after system calls and other operations, such as Tcl_Gets. and why do these procedures even need to exist, you ask? because global variable accesses literally cannot be made across module boundaries on some platforms. it's giving necessary, fr fr. 😭

Tcl_SetErrno sets the errno variable to the value of the errorCode argument. so if you're writing C procedures that wanna hand error info back to their callers via errno, call Tcl_SetErrno instead of setting errno directly. do not go rogue. πŸ’…

Tcl_GetErrno returns the current value of errno. any procedure wishing to access errno should call this procedure instead of accessing errno directly. same energy, but the correct way 🫢

Tcl_ErrnoId and Tcl_ErrnoMsg return string representations of errno values:

  • Tcl_ErrnoId returns a machine-readable textual identifier, such as "EACCES", that corresponds to the current value of errno. πŸ€–
  • Tcl_ErrnoMsg returns a human-readable string, such as "permission denied", that corresponds to the value of its errorCode argument. and that errorCode argument is typically the value returned by Tcl_GetErrno. cute lil pipeline, honestly ✨
⚠️ okay important: the strings returned by these functions are statically allocated, so the caller must not free or modify them. not even a little. don't touch. it's giving hands off πŸ”₯

Tcl_WinConvertError (Windows only, bestie) maps the passed Windows or Winsock error code to a POSIX error and stores it in errno. very translator era of it πŸ’œ


πŸ”‘ KEYWORDS πŸ”‘

errno, error code, global variables


and that's the whole page!! this one's from the Tcl 8.3 era, dated back in the Tcl_SetErrno(3tcl) era of the world, sitting in the Tcl Library Procedures manual πŸ’– thanks for reading bestie, go forth and never set errno directly again πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from