Commits

calaf  committed 98514aa

OSX does not have C getline, use ifstream instead

  • Participants
  • Parent commits 021cfe1
  • Tags CxxUtils-00-00-27

Comments (0)

Files changed (3)

+2009-04-06  Paolo Calafiura  for Ed Moyse
+
+	* tagging CxxUtils-00-00-27
+	* src/procmaps.cxx: OSX does not have C getline, use ifstream instead
+
 2009-04-02  Paolo Calafiura
 
 	* tagging CxxUtils-00-00-26

File src/procmaps.cxx

 #include <algorithm>
-#include <cstdio>
 #include <cstdlib>
 #include <cstring>
+#include <fstream>
 #include "CxxUtils/procmaps.h"
 bool procmaps::s_pmapsLoaded(false);
 procmaps::procmaps_t procmaps::s_pmaps;
 void 
 procmaps::loadMaps(bool dump) {
   procmaps::s_pmaps.clear();
-  FILE* fp = fopen("/proc/self/maps", "r");
-  if (fp) {
-    char* line=0;
-    size_t len=0;
-    while (getline(&line, &len, fp)>0) {
-      if (dump) printf("%s",line);
-      procmaps::s_pmaps.push_back(Entry(line));
-      free(line);
-      line=0;
-    }
-    free(line);
-    fclose(fp);
+  std::ifstream f("/proc/self/maps");
+  const int LMAX=256;
+  char line[LMAX];
+  while ( f.getline(line,LMAX) ) {
+    if (dump) printf("%s",line);
+    procmaps::s_pmaps.push_back(Entry(line));
   }
 }
 

File test/procmaps_test.cxx

 #include <iostream>
 #include <boost/pool/pool_alloc.hpp>
 #include "CxxUtils/procmaps.h"
-// #define DEBUGIT 1
+//#define DEBUGIT 1
 using namespace std;
 void nop() {}
 int main(void) {