if(name) {
tmp_name = strdup(name);
if(!tmp_name) {
- fprintf(stderr, "String duplicating fails\n");
+ PT_ERROR("String duplicating fails");
pt_free_file_info(info);
return NULL;
}
if(dir) {
tmp_dir = strdup(dir);
if(!tmp_dir) {
- fprintf(stderr, "String duplicating fails\n");
+ PT_ERROR("String duplicating fails");
pt_free_file_info(info);
free(tmp_name);
return NULL;
if(file_info->file_type == PT_FILE_TMP) {
char *string = strdup(TEMPLATE);
if(!string) {
- perror("Can't duplicate string with strdup()");
+ PT_ERROR("Can't duplicate string with strdup()");
return NULL;
}
char *drname = dirname(string);
if(g_mkdir_with_parents(drname, S_IRWXU | S_IRWXG) == -1) {
- perror("Can't create nested directory path");
+ PT_ERROR("Can't create nested directory path");
PT_IF_FREE_MEM(string);
return NULL;
}
file = strdup(TEMPLATE);
if (!file) {
- fprintf(stderr, "Can't duplicate string with strdup()\n");
+ PT_ERROR("Can't duplicate string with strdup()");
return NULL;
}
umask(MASK_MODE);
int filedesc = mkstemp(file);
if (filedesc == -1) {
- perror("Can't create temp file");
+ PT_ERROR("Can't create temp file");
PT_IF_FREE_MEM(file);
return NULL;
}
fd = fdopen(filedesc, "w");
if(!fd) {
- fprintf(stderr, "Call fdopen() failed\n");
+ PT_ERROR("Call fdopen() failed");
if(close(filedesc)) {
- fprintf(stderr, "Closing file descriptor fails\n");
+ PT_ERROR("Closing file descriptor fails");
}
int rst = unlink(file);
if(rst) {
- fprintf(stderr, "Unlink temporary file fails\n");
+ PT_ERROR("Unlink temporary file fails");
}
PT_IF_FREE_MEM(file);
return NULL;
}
} else {
- fprintf(stderr, "pt_create_file: Not yet fully supported\n");
+ PT_ERROR("pt_create_file: Not yet fully supported");
return NULL;
}
pt_file *ptfile = (pt_file *)malloc(sizeof(pt_file));
if(!ptfile) {
- fprintf(stderr, "Allocating memory fails\n");
+ PT_ERROR("Allocating memory fails");
if(fclose(fd)) {
PT_ERROR("File error: %s", strerror(errno));
}
char *new_buffer;
char *buffer = malloc(BUFF_SIZE);
if (!buffer) {
- fprintf(stderr, "call malloc() failed: %s\n", strerror(errno));
+ PT_ERROR("call malloc() failed: %s", strerror(errno));
return NULL;
}
memset(buffer, '\0', BUFF_SIZE);
pt_file_info *file_info = pt_create_file_info(NULL, NULL, PT_FILE_TMP);
if(!file_info) {
- fprintf(stderr, "Setting file mode fails\n");
+ PT_ERROR("Setting file mode fails");
return NULL;
}
file = pt_create_file(file_info);
if(!file) {
pt_free_file_info(file_info);
- fprintf(stderr, "Creating file fails\n");
+ PT_ERROR("Creating file fails");
return NULL;
}
uint32_t num = (mod->inform).buffer[i];
numstr = g_ptr_array_index(strings, num);
if(fputs(numstr, file->ptfile) == EOF) {
- fprintf(stderr, "Writing data to temp file failed\n");
+ PT_ERROR("Writing data to temp file failed");
// FIXME: Here we should free memory
pt_free_file_info(file_info);
if(pt_free_file(file, PT_FREE_FILE_DEL)) {
- fprintf(stderr, "Deleting temporary file fails\n");
+ PT_ERROR("Deleting temporary file fails");
}
return NULL;
}
pt_free_file_info(file_info);
if(pt_sync_file(file)) {
- fprintf(stderr, "Synchronize file with storage device fails\n");
+ PT_ERROR("Synchronize file with storage device fails");
if(pt_free_file(file, PT_FREE_FILE_DEL)) {
- fprintf(stderr, "Deleting temporary file fails\n");
+ PT_ERROR("Deleting temporary file fails");
}
return NULL;
}
outstr *string = (outstr*)malloc(sizeof(outstr));
if(!string) {
- fprintf(stderr, "Allocating memory fails\n");
+ PT_ERROR("Allocating memory fails");
return NULL;
}
memset(string, '\0', sizeof(outstr));
if (!value) {
clean_outstr(string);
free(string);
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
return NULL;
}
memset(value, '\0', strln+1);
if (!value) {
clean_outstr(string);
free(string);
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
return NULL;
}
memset(value, '\0', strln+1);
if (!value) {
clean_outstr(string);
free(string);
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
return NULL;
}
memset(value, '\0', strln+1);
outstr *result = NULL;
if (!original) {
- fprintf(stderr, "original is null\n");
+ PT_ERROR("original is null");
return NULL;
}
char *copied = malloc(strlen(original)+1);
if (!copied) {
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
return NULL;
}
char *token = NULL;
char *copied = malloc(strlen(original)+1);
if (!copied) {
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
return NULL;
}
char *full_string = copied;
value = malloc(strlen(token)+1);
if (!value) {
free(full_string);
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
return NULL;
}
strcpy(value, token);
} else {
free(full_string);
free(value);
- printf("String contains unexpected symbols:\n");
- printf("%s\n", original);
+ PT_DEBUG("String contains unexpected symbols: %s", original);
return NULL;
}
}
} else {
free(full_string);
- printf("String which contains %s is not correct", original);
+ PT_DEBUG("String which contains %s is not correct", original);
return NULL;
}
}
drv = (drvm *)calloc(1, sizeof(drvm));
if (!drv) {
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
return NULL;
}
result = fread(&len, sizeof(uint32_t), 1, fd);
if (result != 1) {
- fprintf(stderr, "Can't read data from file\n");
+ PT_ERROR("Can't read data from file");
pt_free_drvm(drv);
return NULL;
}
if(len == 0 || len > UINT32_MAX) {
- fprintf(stderr, "Invalid length(%d)\n", len);
+ PT_ERROR("Invalid length(%d)", len);
pt_free_drvm(drv);
return NULL;
}
result = fread(&len, sizeof(uint32_t), 1, fd);
if (result != 1) {
- fprintf(stderr, "Can't read data from file\n");
+ PT_ERROR("Can't read data from file");
void *ptr = g_ptr_array_free(models, TRUE);
if(ptr) {
- perror("freeing memory fails");
+ PT_ERROR("freeing memory fails");
}
free(drv);
return NULL;
}
if (len == 0 || len > UINT32_MAX) {
- fprintf(stderr, "Invalid length(%d)\n", len);
+ PT_ERROR("Invalid length(%d)", len);
pt_free_drvm(drv);
return NULL;
}
for (int i = 0; i < length; ++i) {
string = NULL;
if((read = getline(&string, &size_buffer, fd)) == -1) {
- fprintf(stderr, "Can't read line from file\n");
+ PT_ERROR("Can't read line from file");
void *ptr = g_ptr_array_free(strings, TRUE);
if(ptr) {
- perror("freeing memory fails");
+ PT_ERROR("freeing memory fails");
}
ptr = g_ptr_array_free(models, TRUE);
if(ptr) {
- perror("freeing memory fails");
+ PT_ERROR("freeing memory fails");
}
free(drv);
return NULL;
mod = malloc(sizeof(model));
uint32_t len;
if (!mod) {
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
return NULL;
}
result = fread(&len, sizeof(uint32_t), 1, fd);
if(result != 1) {
- fprintf(stderr, "Can't read data from file\n");
+ PT_ERROR("Can't read data from file");
pt_free_model(mod);
return NULL;
}
result = fread(&len, sizeof(uint32_t), 1, fd);
if(result != 1) {
- fprintf(stderr, "Can't read data from file\n");
+ PT_ERROR("Can't read data from file");
pt_free_model(mod);
return NULL;
}
if(len == 0 || len > UINT32_MAX) {
- fprintf(stderr, "Invalid length(%d)\n", len);
+ PT_ERROR("Invalid length(%d)", len);
pt_free_model(mod);
return NULL;
}
length = len;
if ((length >> 30) > 0)
{
- fprintf(stderr, "Integer overflow\n");
+ PT_ERROR("Integer overflow");
pt_free_model(mod);
return NULL;
}
uint32_t size_buffer = length * sizeof(uint32_t);
if(!((mod->product).buffer = malloc(size_buffer))) {
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
pt_free_model(mod);
return NULL;
}
result = fread((mod->product).buffer, size_buffer, 1, fd);
if(result != 1) {
- fprintf(stderr, "Can't read data from file\n");
+ PT_ERROR("Can't read data from file");
pt_free_model(mod);
return NULL;
}
result = fread(&len, sizeof(uint32_t), 1, fd);
if(result != 1) {
- fprintf(stderr, "Can't read data from file\n");
+ PT_ERROR("Can't read data from file");
pt_free_model(mod);
return NULL;
}
if(len == 0 || len > UINT32_MAX) {
- fprintf(stderr, "Invalid length(%d)\n", len);
+ PT_ERROR("Invalid length(%d)", len);
pt_free_model(mod);
return NULL;
}
length = len;
if ((length>>(32 - sizeof(uint32_t))) > 0)
{
- fprintf(stderr, "Integer overflow\n");
+ PT_ERROR("Integer overflow");
pt_free_model(mod);
return NULL;
}
size_buffer = length * sizeof(uint32_t);
if(!(mod->inform.buffer = malloc(size_buffer))) {
- fprintf(stderr, "Can't allocate memory\n");
+ PT_ERROR("Can't allocate memory");
pt_free_model(mod);
return NULL;
}
mod->inform.len = length;
result = fread(mod->inform.buffer, size_buffer, 1, fd);
if(result != 1) {
- fprintf(stderr, "Can't read data from file\n");
+ PT_ERROR("Can't read data from file");
pt_free_model(mod);
return NULL;
}
char *output = pt_exec_ppdc(file);
if(!output) {
// Handle error
- PT_ERROR("Executing ppdc fails\n");
+ PT_ERROR("Executing ppdc fails");
if(pt_free_file(file, PT_FREE_FILE_DEL)) {
- fprintf(stderr, "Freeing memory fails\n");
+ PT_ERROR("[%s] Can't free memory", search);
}
return NULL;
}
if(pt_free_file(file, PT_FREE_FILE_DEL)) {
- fprintf(stderr, "Freeing memory fails\n");
+ PT_ERROR("Freeing memory fails");
free(output);
return NULL;
}