home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cons-010.zip / Console / src / common / syslib.c < prev    next >
C/C++ Source or Header  |  1997-07-30  |  3KB  |  75 lines

  1. /******************************************************************************\
  2. |*                                                                            *|
  3. |* Operating system-related functions                                         *|
  4. |* Copyright (C) 1997 by FRIENDS software                                     *|
  5. |* All Rights Reserved                                                        *|
  6. |* Portability: OS/2                                                          *|
  7. |*                                                                            *|
  8. |* This program is free software; you can redistribute it and/or modify       *|
  9. |* it under the terms of the GNU General Public License as published by       *|
  10. |* the Free Software Foundation; either version 2 of the License, or          *|
  11. |* (at your option) any later version.                                        *|
  12. |*                                                                            *|
  13. |* This program is distributed in the hope that it will be useful,            *|
  14. |* but WITHOUT ANY WARRANTY; without even the implied warranty of             *|
  15. |* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *|
  16. |* GNU General Public License for more details.                               *|
  17. |*                                                                            *|
  18. |* You should have received a copy of the GNU General Public License          *|
  19. |* along with this program; if not, write to the Free Software                *|
  20. |* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA  *|
  21. |*                                                                            *|
  22. \******************************************************************************/
  23.  
  24. #define INCL_DOSPROCESS
  25. #include <os2.h>
  26. #include <string.h>
  27. #include <malloc.h>
  28. #include "strop.h"
  29. #include "syslib.h"
  30.  
  31. char *Environment()
  32. {
  33.  PTIB tib;
  34.  PPIB pib;
  35.  DosGetInfoBlocks(&tib, &pib);
  36.  return pib->pib_pchenv;
  37. }
  38.  
  39. char *SourceName()
  40. {
  41.  int i;
  42.  char *RetS;
  43.  char *Env = Environment();
  44.  
  45.  do Env++; while ((Env[-1] != 0) || (Env[0] != 0));
  46.  do Env++; while (Env[0] != 0);
  47.  Env++;
  48.  i = strlen(Env);
  49.  RetS = malloc(i);
  50.  if (RetS) strcpy(RetS, Env);
  51.  return RetS;
  52. }
  53.  
  54. char *SourcePath()
  55. {
  56.  int i;
  57.  char *RetS;
  58.  char *Env = Environment();
  59.  
  60.  do Env++; while ((Env[-1] != 0) || (Env[0] != 0));
  61.  do Env++; while (Env[0] != 0);
  62.  
  63.  Env++; RetS = Env + strlen(Env);
  64.  while ((RetS > Env) && (strlast(RetS[-1], PATHSEP) < 0)) RetS--;
  65.  
  66.  i = RetS - Env;
  67.  RetS = malloc(i + 1);
  68.  if (RetS)
  69.  {
  70.   strncpy(RetS, Env, i);
  71.   RetS[i] = 0;
  72.  }
  73.  return RetS;
  74. }
  75.