/****************************************************************************** purpose: returns a new string consisting of s+t ******************************************************************************/ char *strdup_together(const char *s, const char *t) { char *both; size_t siz; if (s == NULL) { if (t == NULL) return NULL; return strdup(t); } if (t == NULL) return strdup(s); if (0) diagnostics(1, "'%s' + '%s'", s, t); siz = strlen(s) + strlen(t) + 1; both = (char *) malloc(siz); if (both == NULL) diagnostics(ERROR, "Could not allocate memory for both strings."); my_strlcpy(both, s, siz); my_strlcat(both, t, siz); return both; }
static bool dumpCallback(const google_breakpad::MinidumpDescriptor& descriptor, void* context, bool succeeded) { //printf("Wrote minidump to: %s\n", descriptor.path()); if (succeeded) { sys_write(STDOUT_FILENO, "Wrote minidump to: ", 19); } else { sys_write(STDOUT_FILENO, "Failed to write minidump to: ", 29); } sys_write(STDOUT_FILENO, descriptor.path(), my_strlen(descriptor.path())); sys_write(STDOUT_FILENO, "\n", 1); if (!succeeded) { return succeeded; } my_strlcpy(dumpStoragePath, descriptor.path(), sizeof(dumpStoragePath)); my_strlcat(dumpStoragePath, ".txt", sizeof(dumpStoragePath)); int extra = sys_open(dumpStoragePath, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR); if (extra == -1) { sys_write(STDOUT_FILENO, "Failed to open metadata file!\n", 30); return succeeded; } sys_write(extra, "-------- CONFIG BEGIN --------", 30); sys_write(extra, "\nMap=", 5); sys_write(extra, crashMap, my_strlen(crashMap)); sys_write(extra, "\nGamePath=", 10); sys_write(extra, crashGamePath, my_strlen(crashGamePath)); sys_write(extra, "\nCommandLine=", 13); sys_write(extra, crashCommandLine, my_strlen(crashCommandLine)); sys_write(extra, "\nSourceModPath=", 15); sys_write(extra, crashSourceModPath, my_strlen(crashSourceModPath)); sys_write(extra, "\nGameDirectory=", 15); sys_write(extra, crashGameDirectory, my_strlen(crashGameDirectory)); sys_write(extra, "\nExtensionVersion=", 18); sys_write(extra, SM_VERSION, my_strlen(SM_VERSION)); sys_write(extra, "\nExtensionBuild=", 16); sys_write(extra, SM_BUILD_UNIQUEID, my_strlen(SM_BUILD_UNIQUEID)); sys_write(extra, steamInf, my_strlen(steamInf)); sys_write(extra, "\n-------- CONFIG END --------\n", 30); if (GetSpew) { GetSpew(spewBuffer, sizeof(spewBuffer)); if (my_strlen(spewBuffer) > 0) { sys_write(extra, "-------- CONSOLE HISTORY BEGIN --------\n", 40); sys_write(extra, spewBuffer, my_strlen(spewBuffer)); sys_write(extra, "-------- CONSOLE HISTORY END --------\n", 38); } } #if 0 char pis[64]; char pds[32]; for (unsigned i = 0; i < plugin_count; ++i) { PluginInfo *p = &plugins[i]; if (p->serial == 0) continue; my_uitos(pds, i, my_uint_len(i)); pds[my_uint_len(i)] = '\0'; my_strlcpy(pis, "plugin[", sizeof(pis)); my_strlcat(pis, pds, sizeof(pis)); my_strlcat(pis, "].", sizeof(pis)); sys_write(extra, pis, my_strlen(pis)); sys_write(extra, "filename=", 9); sys_write(extra, p->filename, my_strlen(p->filename)); sys_write(extra, "\n", 1); sys_write(extra, pis, my_strlen(pis)); sys_write(extra, "name=", 5); sys_write(extra, p->name, my_strlen(p->name)); sys_write(extra, "\n", 1); sys_write(extra, pis, my_strlen(pis)); sys_write(extra, "author=", 7); sys_write(extra, p->author, my_strlen(p->author)); sys_write(extra, "\n", 1); sys_write(extra, pis, my_strlen(pis)); sys_write(extra, "description=", 12); sys_write(extra, p->description, my_strlen(p->description)); sys_write(extra, "\n", 1); sys_write(extra, pis, my_strlen(pis)); sys_write(extra, "version=", 8); sys_write(extra, p->version, my_strlen(p->version)); sys_write(extra, "\n", 1); sys_write(extra, pis, my_strlen(pis)); sys_write(extra, "url=", 4); sys_write(extra, p->url, my_strlen(p->url)); sys_write(extra, "\n", 1); } #endif sys_close(extra); return succeeded; }
/* ----------------------------------------------------------------------------- Function: Cmd_Alias_f -Creates a new command that executes a command string (possibly ; seperated). Parameters: Nothing. Returns: Nothing. Notes: ----------------------------------------------------------------------------- */ PRIVATE void Cmd_Alias_f( void ) { cmdalias_t *a; char cmd[ 1024 ]; int i, c; char *s; W32 hashid; if( Cmd_Argc() == 1 ) { Com_Printf( "Current alias commands:\n" ); for( a = cmd_alias ; a ; a = a->next ) { Com_Printf( "%s : %s\n", a->name, a->value ); } return; } s = Cmd_Argv( 1 ); if( strlen( s ) >= MAX_ALIAS_NAME ) { Com_Printf( "Alias name is too long\n" ); return; } hashid = my_strhash( s ); // if the alias already exists, reuse it for( a = cmd_alias ; a ; a = a->next ) { if( hashid == a->id ) { Z_Free( a->value ); break; } } if( ! a ) { a = Z_Malloc( sizeof( cmdalias_t ) ); a->next = cmd_alias; cmd_alias = a; } my_strlcpy( a->name, s, sizeof( a->name ) ); a->id = hashid; // copy the rest of the command line cmd[ 0 ] = '\0'; // start out with a NUL-terminated string c = Cmd_Argc(); for( i = 2; i < c; ++i ) { my_strlcat( cmd, Cmd_Argv( i ), sizeof( cmd ) ); if( i != (c - 1) ) { my_strlcat( cmd, " ", sizeof( cmd ) ); } } my_strlcat( cmd, "\n", sizeof( cmd ) ); a->value = my_CopyString( cmd ); }
/* ----------------------------------------------------------------------------- Function: Cbuf_AddLateCommands -Adds command line parameters as script statements. Parameters: Nothing. Returns: true if any late commands were added, otherwise false. Notes: Commands lead with a + and continue until another + or - application.exe +map amlev1 Returns true if any late commands were added, which will keep the demoloop from immediately starting ----------------------------------------------------------------------------- */ PUBLIC _boolean Cbuf_AddLateCommands( void ) { int i, j; int s; char *text, *build, c; int argc; _boolean ret; // build the combined string to parse from s = 0; argc = COM_Argc(); for( i = 1; i < argc; ++i ) { s += strlen( COM_Argv( i ) ) + 1; } if( ! s ) { return false; } text = Z_Malloc( s + 1 ); text[ 0 ] = '\0'; // Start with a NUL-terminated string. for( i = 1; i < argc; ++i ) { my_strlcat( text, COM_Argv( i ), s ); if( i != argc-1 ) { my_strlcat( text, " ", s ); } } // pull out the commands build = Z_Malloc( s + 1 ); build[ 0 ] = '\0'; // Start with a NUL-terminated string. for( i = 0; i < s-1; ++i ) { if( text[ i ] == '+' ) { i++; for( j = i ; (text[ j ] != '+') && (text[ j ] != '-') && (text[ j ] != 0) ; j++ ) ; c = text[ j ]; text[ j ] = 0; my_strlcat( build, text+i, s+1 ); my_strlcat( build, "\n", s+1 ); text[ j ] = c; i = j - 1; } } ret = (build[ 0 ] != 0); if( ret ) { Cbuf_AddText (build); } Z_Free( text ); Z_Free( build ); return ret; }