/* ******************************************************************* * * * Copyright (c) L-DGO/MIT/JGOFS * * * * * * File : ex.c * * * * Purpose : * * * * Version Number : 1.3 * * * * Date Developer * * ---- --------- * * * * Sat Oct 17 1992 10.00 Glenn Flierl * * * * Revision History : * 25 Jan 12. WJS Replace getwd with getcwd per "deprecated" warning [begin 1.3] 22 May 08. WJS Include some .h files to get rid of compiler diagnostics Calculate the size of the com buffer and allocate that much (replaces fixed size 160 char buffer) Abort on some failures [begin 1.2] * * * * ******************************************************************* */ #include #include #include #include void ex_(stuff) char *stuff; { char *com; size_t bufsiz; /* "cd " longest getwd ";" \0 */ bufsiz = 3 + (PATH_MAX+1) + 1 + strlen(stuff) + 1; com = (char *)malloc(bufsiz); if (com == NULL) abort(); strcpy(com,"cd "); if (getcwd(com+3,bufsiz-3) == NULL) abort(); strcat(com,";"); strcat(com,stuff); system(com); return; }