in astra-sim-alibabacloud/astra-sim/workload/CSVWriter.cc [136:192]
void CSVWriter::write_cell(int row, int column, std::string data) {
std::string str = "";
std::string tmp;
int status = 1;
int fildes = -1;
do {
fildes = open((path + name).c_str(), O_RDWR);
} while (fildes == -1);
do {
status = lockf(fildes, F_TLOCK, (off_t)1000000);
} while (status != 0);
char buf[1];
while (row > 0) {
status = read(fildes, buf, 1);
str = str + (*buf);
if (*buf == '\n') {
row--;
}
}
while (column > 0) {
status = read(fildes, buf, 1);
str = str + (*buf);
if (*buf == ',') {
column--;
}
if (*buf == '\n') {
std::cerr << "fatal error in inserting cewll!" << std::endl;
exit(1);
}
}
str = str + data;
while (read(fildes, buf, 1)) {
str = str + (*buf);
}
do {
lseek(fildes, 0, SEEK_SET);
status = write(fildes, str.c_str(), str.length());
} while (status != str.length());
do {
status = lseek(fildes, 0, SEEK_SET);
} while (status == -1);
do {
status = lockf(fildes, F_ULOCK, (off_t)1000000);
} while (status != 0);
do {
status = close(fildes);
} while (status == -1);
return;
}