Skip to content

Commit

Permalink
Pass success flag to plugins, include changes
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyHackGUT committed Mar 10, 2020
1 parent 6f14a3a commit 9ac8b28
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
11 changes: 10 additions & 1 deletion package/scripting/include/env_variables.inc
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@
* @param szName The environment variable name.
* @param szBuffer Buffer where value should be written.
* @param iBufferLength Maximum size of the buffer.
* @param bExists The ref to variable where will be written
* information about presence environment variable.
* @return The written bytes count.
*/
native int GetEnvironmentVariable(const char[] szName, char[] szBuffer, int iBufferLength);
native int GetEnvironmentVariable(const char[] szName, char[] szBuffer, int iBufferLength, bool &bExists = false);

/**
* Do not edit below this line!
Expand All @@ -62,3 +64,10 @@ public Extension __ext_env_variables =
required = 0,
#endif
};

#if !defined REQUIRE_EXTENSIONS
public void __ext_env_variables_SetNTVOptional()
{
MarkNativeAsOptional("GetEnvironmentVariable");
}
#endif
7 changes: 7 additions & 0 deletions src/natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ static cell_t sm_getenv(SourcePawn::IPluginContext *pContext, const cell_t *para
char *value = getenv(name);

cell_t is_success = (value != NULL) ? 1 : 0;
if (params[0] > 3)
{
cell_t *addr;
pContext->LocalToPhysAddr(params[4], &addr);
*addr = is_success;
}

if (value != NULL)
{
size_t numBytes;
Expand Down
2 changes: 1 addition & 1 deletion src/smsdk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
/* Basic information exposed publicly */
#define SMEXT_CONF_NAME "Environment Variables"
#define SMEXT_CONF_DESCRIPTION "Extension what implements getenv() for SourcePawn plugins"
#define SMEXT_CONF_VERSION "1.0.0.0"
#define SMEXT_CONF_VERSION "1.0.0.1"
#define SMEXT_CONF_AUTHOR "CrazyHackGUT aka Kruzya"
#define SMEXT_CONF_URL "https://kruzya.me/"
#define SMEXT_CONF_LOGTAG "ENV"
Expand Down

0 comments on commit 9ac8b28

Please sign in to comment.