Mercurial > libpst
comparison src/libpst.c @ 325:cb67b335afcc
patches from debian
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 18 Jan 2013 08:05:08 -0800 |
parents | c4537664ff50 |
children | c507af52515a |
comparison
equal
deleted
inserted
replaced
324:6b1399ab2d46 | 325:cb67b335afcc |
---|---|
287 static int pst_stricmp(char *a, char *b); | 287 static int pst_stricmp(char *a, char *b); |
288 static int pst_strincmp(char *a, char *b, size_t x); | 288 static int pst_strincmp(char *a, char *b, size_t x); |
289 static char* pst_wide_to_single(char *wt, size_t size); | 289 static char* pst_wide_to_single(char *wt, size_t size); |
290 | 290 |
291 | 291 |
292 static char *pst_getcwd(void) { | |
293 char *cwd; | |
294 #ifdef HAVE_GET_CURRENT_DIR_NAME | |
295 cwd = get_current_dir_name(); | |
296 #else | |
297 cwd = pst_malloc(PATH_MAX+1); | |
298 getcwd(cwd, PATH_MAX+1); | |
299 #endif | |
300 return cwd; | |
301 } | |
302 | |
292 | 303 |
293 int pst_open(pst_file *pf, const char *name, const char *charset) { | 304 int pst_open(pst_file *pf, const char *name, const char *charset) { |
294 int32_t sig; | 305 int32_t sig; |
295 | 306 |
296 pst_unicode_init(); | 307 pst_unicode_init(); |
359 pf->index1 = pst_getIntAtPos(pf, INDEX_POINTER); | 370 pf->index1 = pst_getIntAtPos(pf, INDEX_POINTER); |
360 DEBUG_INFO(("Pointer1 is %#"PRIx64", back pointer2 is %#"PRIx64"\n", pf->index1, pf->index1_back)); | 371 DEBUG_INFO(("Pointer1 is %#"PRIx64", back pointer2 is %#"PRIx64"\n", pf->index1, pf->index1_back)); |
361 | 372 |
362 DEBUG_RET(); | 373 DEBUG_RET(); |
363 | 374 |
364 pf->cwd = pst_malloc(PATH_MAX+1); | 375 pf->cwd = pst_getcwd(); |
365 getcwd(pf->cwd, PATH_MAX+1); | |
366 pf->fname = strdup(name); | 376 pf->fname = strdup(name); |
367 return 0; | 377 return 0; |
368 } | 378 } |
369 | 379 |
370 | 380 |
371 int pst_reopen(pst_file *pf) { | 381 int pst_reopen(pst_file *pf) { |
372 char cwd[PATH_MAX]; | 382 char *cwd; |
373 if (!getcwd(cwd, PATH_MAX)) return -1; | 383 cwd = pst_getcwd(); |
374 if (chdir(pf->cwd)) return -1; | 384 if (cwd == NULL) return -1; |
375 if (!freopen(pf->fname, "rb", pf->fp)) return -1; | 385 if (chdir(pf->cwd)) goto err; |
376 if (chdir(cwd)) return -1; | 386 if (!freopen(pf->fname, "rb", pf->fp)) goto err; |
387 if (chdir(cwd)) goto err; | |
388 free(cwd); | |
377 return 0; | 389 return 0; |
390 err: | |
391 free(cwd); | |
392 return -1; | |
378 } | 393 } |
379 | 394 |
380 | 395 |
381 int pst_close(pst_file *pf) { | 396 int pst_close(pst_file *pf) { |
382 DEBUG_ENT("pst_close"); | 397 DEBUG_ENT("pst_close"); |