示例#1
0
ConfigVar ConfigReader::toVar() const {
  // write everything to a ConfigVar, then output to disk
  ConfigVar out;
  out.writeInt(vars.size());
  map<string, ConfigVar>::const_iterator it;
  for (it = vars.begin(); it != vars.end(); ++it) {
    out.writeInt(it->first.size());
    out.write((unsigned char *)it->first.data(), it->first.size());
    out.writeInt(it->second.size());
    out.write((unsigned char *)it->second.buffer(), it->second.size());
  }

  return out;
}
示例#2
0
// read the entire file into a ConfigVar instance and then use that to decode
// into mapped variables.
bool ConfigReader::load(const char *fileName) {
  struct stat_st stbuf;
  memset(&stbuf, 0, sizeof(struct stat_st));
  if (unix::lstat(fileName, &stbuf) != 0) return false;

  int size = stbuf.st_size;

  int fd = unix::open(fileName, O_RDONLY);
  if (fd < 0) return false;

  char *buf = new char[size];

  int res = ::_read(fd, buf, size);
  close(fd);

  if (res != size) {
    rWarning("Partial read of config file, expecting %i bytes, got %i", size,
             res);
    delete[] buf;
    return false;
  }

  ConfigVar in;
  in.write((unsigned char *)buf, size);
  delete[] buf;

  return loadFromVar(in);
}
示例#3
0
// read the entire file into a ConfigVar instance and then use that to decode
// into mapped variables.
bool ConfigReader::load(const char *fileName) {
  struct stat stbuf;
  memset(&stbuf, 0, sizeof(struct stat));
  if (lstat(fileName, &stbuf) != 0) return false;

  int size = stbuf.st_size;

  int fd = open(fileName, O_RDONLY);
  if (fd < 0) return false;

  char *buf = new char[size];

  int res = ::read(fd, buf, size);
  close(fd);

  if (res != size) {
    RLOG(WARNING) << "Partial read of config file, expecting " << size
                  << " bytes, got " << res;
    delete[] buf;
    return false;
  }

  ConfigVar in;
  in.write((unsigned char *)buf, size);
  delete[] buf;

  return loadFromVar(in);
}