/[projects]/smsdaemon/Util.cpp
ViewVC logotype

Diff of /smsdaemon/Util.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 193 by torben, Wed Dec 17 23:43:26 2008 UTC revision 203 by torben, Fri Dec 19 07:03:34 2008 UTC
# Line 10  Line 10 
10  #include <stdexcept>  #include <stdexcept>
11  #include <time.h>  #include <time.h>
12  #include <sys/time.h>  #include <sys/time.h>
13    #include <sys/types.h>
14    #include <sys/wait.h>
15    #include <errno.h>
16  #include <stdlib.h>  #include <stdlib.h>
17    
18  #include <cstring>  #include <cstring>
# Line 266  namespace Util Line 269  namespace Util
269    
270          string str_gsm2latin(string str)          string str_gsm2latin(string str)
271          {          {
272                  for (unsigned i=0; i<str.size(); i++) {                  for (unsigned i=0; i<str.size(); i++)
273                    {
274                          str.at(i) = char_def_alphabet_decode(str.at(i));                          str.at(i) = char_def_alphabet_decode(str.at(i));
275                  }                  }
276                  return str;                  return str;
# Line 274  namespace Util Line 278  namespace Util
278    
279          string str_latin2gsm(string str)          string str_latin2gsm(string str)
280          {          {
281                  for (unsigned i=0; i<str.size(); i++) {                  for (unsigned i=0; i<str.size(); i++)
282                    {
283                          str.at(i) = char_def_alphabet_encode(str.at(i));                          str.at(i) = char_def_alphabet_encode(str.at(i));
284                  }                  }
285                  return str;                  return str;
# Line 418  namespace Util Line 423  namespace Util
423                  return (pclose(p));                  return (pclose(p));
424          }          }
425    
426            int my_system2 (const char *command)
427            {
428                    int pid, status;
429    
430                    if (command == 0)
431                            return 1;
432            //      printf("forking ...\n");
433                    pid = fork();
434                    if (pid == -1)
435                            return -1;
436                    if (pid == 0)
437                    {
438                            char *argv[4];
439                            argv[0] = (char*) "sh";
440                            argv[1] = (char*) "-c";
441                            argv[2] = (char *) command;
442                            argv[3] = 0;
443            //              printf("chaining ...\n");
444                            execve("/bin/sh", argv, environ);
445            //              printf("Chaining failed!\n");
446                            exit(127);
447                    }
448                    do
449                    {
450            //              printf("Waiting on PID: %d\n",pid);
451                            if (waitpid(pid, &status, 0) == -1)
452                            {
453            //                      printf("erc: %d\n",errno);
454                                    if (errno != EINTR)
455                                            return -1;
456                            }
457                            else
458                            {
459            //                      printf("status: %d\n",status);
460                                    return status;
461                            }
462                    }
463                    while (1);
464            }
465    
466    
467          string readfile(string filename)          string readfile(string filename)
468          {          {
469                  string str;                  string str;

Legend:
Removed from v.193  
changed lines
  Added in v.203

  ViewVC Help
Powered by ViewVC 1.1.20