Changeset 1190:eb9a8f15de24
- Timestamp:
- 03/23/09 09:58:31 (3 years ago)
- Branch:
- default
- Location:
- trunk
- Files:
-
- 10 edited
- 1 copied
-
include/libdodo/ioFileFifo.h (modified) (2 diffs)
-
include/libdodo/ioFileRegular.h (modified) (2 diffs)
-
include/libdodo/ioFileTemp.h (modified) (2 diffs)
-
include/libdodo/ioPipe.h (modified) (2 diffs)
-
include/libdodo/ioStdio.h (modified) (1 diff)
-
src/ioFile.inline (copied) (copied from trunk/src/ioFileRegular.cc) (2 diffs)
-
src/ioFileFifo.cc (modified) (40 diffs)
-
src/ioFileRegular.cc (modified) (48 diffs)
-
src/ioFileTemp.cc (modified) (35 diffs)
-
src/ioPipe.cc (modified) (39 diffs)
-
src/ioStdio.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/libdodo/ioFileFifo.h
r1183 r1190 40 40 namespace io 41 41 { 42 struct __file; 43 42 44 namespace file 43 45 { … … 180 182 short mode; ///< file open mode[see fileOpenmodeEnum] 181 183 182 void *handler; ///< file handler184 __file *handle; ///< file handle 183 185 184 186 bool blocked; ///< true if stream is blocked -
trunk/include/libdodo/ioFileRegular.h
r1183 r1190 40 40 namespace io 41 41 { 42 struct __file; 43 42 44 namespace file 43 45 { … … 185 187 short mode; ///< file open mode[see fileOpenmodeEnum] 186 188 187 void *handler; ///< file handler189 __file *handle; ///< file handle 188 190 }; 189 191 }; -
trunk/include/libdodo/ioFileTemp.h
r1183 r1190 39 39 namespace io 40 40 { 41 struct __file; 42 41 43 namespace file 42 44 { … … 159 161 private: 160 162 161 void *handler; ///< file handler163 __file *handle; ///< file handle 162 164 }; 163 165 }; -
trunk/include/libdodo/ioPipe.h
r1189 r1190 43 43 struct __peerInfo; 44 44 }; 45 46 struct __file; 45 47 46 48 /** … … 160 162 virtual void _writeStream(const char * const data); 161 163 162 void*in; ///< input stream descriptor163 void*out; ///< output stream descriptor164 __file *in; ///< input stream descriptor 165 __file *out; ///< output stream descriptor 164 166 165 167 private: -
trunk/include/libdodo/ioStdio.h
r1166 r1190 31 31 #define _IOSTDIO_H_ 1 32 32 33 #include <fcntl.h>34 #include <sys/un.h>35 #include <sys/socket.h>36 #include <netinet/in.h>37 #include <arpa/inet.h>38 #include <netdb.h>39 40 33 #include <libdodo/directives.h> 41 34 42 #include <libdodo/types.h>43 35 #include <libdodo/ioPipe.h> 44 36 -
trunk/src/ioFile.inline
r1183 r1190 1 2 1 /*************************************************************************** 3 * ioFile Regular.cc2 * ioFile.inline 4 3 * 5 * Wed Oct 8 01:44:18 20056 * Copyright 200 5Ni@m4 * Mon Mar 23 10:23:18 2009 5 * Copyright 2009 Ni@m 7 6 * niam.niam@gmail.com 8 7 ****************************************************************************/ … … 31 30 #include <libdodo/directives.h> 32 31 33 #include <unistd.h> 34 #include <sys/types.h> 35 #include <sys/stat.h> 32 #include <stdio.h> 36 33 37 #include <libdodo/ioFileRegular.h> 38 #include <libdodo/toolsFilesystem.h> 39 #include <libdodo/ioFileRegularEx.h> 40 #include <libdodo/types.h> 41 #include <libdodo/pcSyncProtector.h> 42 #include <libdodo/ioChannel.h> 43 44 using namespace dodo::io::file; 45 46 regular::regular(short protection) : overwrite(false), 47 pos(0), 48 blockOffset(true), 49 append(false), 50 handler(NULL), 51 channel(protection) 34 namespace dodo 52 35 { 53 #ifndef IO_WO_XEXEC 54 collectedData.setExecObject(XEXEC_OBJECT_IOFILEREGULAR); 55 #endif 56 } 57 58 //------------------------------------------------------------------- 59 60 regular::regular(const dodoString &a_path, 61 short a_mode, 62 short protection) : overwrite(false), 63 pos(0), 64 blockOffset(true), 65 append(false), 66 handler(NULL), 67 path(a_path), 68 mode(a_mode), 69 channel(protection) 70 { 71 #ifndef IO_WO_XEXEC 72 collectedData.setExecObject(XEXEC_OBJECT_IOFILEREGULAR); 73 #endif 74 75 bool exists(false); 76 77 if (path.size() == 0) 36 namespace io 78 37 { 79 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_LIBDODO, REGULAREX_WRONGFILENAME, IOFILEREGULAREX_WRONGFILENAME_STR, __LINE__, __FILE__, path); 80 } 81 else 82 { 83 struct stat st; 84 85 if (::lstat(path.c_str(), &st) == -1) 38 /** 39 * @struct __file 40 * @brief defines file handle 41 */ 42 struct __file 86 43 { 87 if (errno != ENOENT) 44 /** 45 * constructor 46 */ 47 __file() : file(NULL) 88 48 { 89 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path);90 }91 }92 else93 {94 exists = true;95 }96 97 if (exists && !S_ISREG(st.st_mode) && !S_ISBLK(st.st_mode))98 {99 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_LIBDODO, REGULAREX_WRONGFILENAME, IOFILEREGULAREX_WRONGFILENAME_STR, __LINE__, __FILE__, path);100 }101 102 switch (mode)103 {104 case REGULAR_OPENMODE_READ_WRITE:105 106 handler = fopen(path.c_str(), "r+");107 if (handler == NULL)108 {109 handler = fopen(path.c_str(), "w+");110 }111 112 break;113 114 case REGULAR_OPENMODE_READ_WRITE_TRUNCATE:115 116 handler = fopen(path.c_str(), "w+");117 118 break;119 120 case REGULAR_OPENMODE_APPEND:121 122 handler = fopen(path.c_str(), "a");123 124 break;125 126 case REGULAR_OPENMODE_READ_ONLY:127 default:128 129 handler = fopen(path.c_str(), "r");130 }131 }132 133 if (handler == NULL)134 {135 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path);136 }137 138 if (!exists)139 {140 tools::filesystem::chmod(path, DEFAULT_FILE_PERM);141 }142 }143 144 //-------------------------------------------------------------------145 146 regular::regular(const regular &fd) : overwrite(fd.overwrite),147 path(fd.path),148 pos(fd.pos),149 blockOffset(fd.blockOffset),150 append(fd.append),151 mode(fd.mode),152 handler(NULL),153 channel(fd.protection)154 155 {156 #ifndef IO_WO_XEXEC157 collectedData.setExecObject(XEXEC_OBJECT_IOFILEREGULAR);158 #endif159 160 inSize = fd.inSize;161 outSize = fd.outSize;162 163 if (fd.handler != NULL)164 {165 int oldDesc, newDesc;166 167 oldDesc = fileno((FILE *)fd.handler);168 if (oldDesc == -1)169 {170 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);171 }172 173 newDesc = dup(oldDesc);174 if (newDesc == -1)175 {176 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);177 }178 179 switch (mode)180 {181 case REGULAR_OPENMODE_READ_WRITE:182 case REGULAR_OPENMODE_READ_WRITE_TRUNCATE:183 184 handler = fdopen(newDesc, "r+");185 186 break;187 188 case REGULAR_OPENMODE_APPEND:189 190 handler = fdopen(newDesc, "a");191 192 break;193 194 case REGULAR_OPENMODE_READ_ONLY:195 default:196 197 handler = fdopen(newDesc, "r");198 }199 200 if (handler == NULL)201 {202 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);203 }204 }205 }206 207 //-------------------------------------------------------------------208 209 regular::~regular()210 {211 if (handler != NULL)212 {213 fclose((FILE *)handler);214 }215 }216 217 //-------------------------------------------------------------------218 219 int220 regular::getInDescriptor() const221 {222 pc::sync::protector pg(keeper);223 224 if (handler == NULL)225 {226 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_GETINDESCRIPTOR, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path);227 }228 229 return fileno((FILE *)handler);230 }231 232 //-------------------------------------------------------------------233 234 int235 regular::getOutDescriptor() const236 {237 pc::sync::protector pg(keeper);238 239 if (handler == NULL)240 {241 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_GETOUTDESCRIPTOR, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path);242 }243 244 return fileno((FILE *)handler);245 }246 247 //-------------------------------------------------------------------248 249 void250 regular::clone(const regular &fd)251 {252 pc::sync::protector pg(keeper);253 254 if (handler != NULL)255 {256 if (fclose((FILE *)handler) != 0)257 {258 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);259 }260 261 handler = NULL;262 }263 264 overwrite = fd.overwrite;265 path = fd.path;266 mode = fd.mode;267 pos = fd.pos;268 blockOffset = fd.blockOffset;269 append = fd.append;270 inSize = fd.inSize;271 outSize = fd.outSize;272 273 if (fd.handler != NULL)274 {275 int oldDesc, newDesc;276 277 oldDesc = fileno((FILE *)fd.handler);278 if (oldDesc == -1)279 {280 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);281 }282 283 newDesc = dup(oldDesc);284 if (newDesc == -1)285 {286 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);287 }288 289 switch (mode)290 {291 case REGULAR_OPENMODE_READ_WRITE:292 case REGULAR_OPENMODE_READ_WRITE_TRUNCATE:293 294 handler = fdopen(newDesc, "r+");295 296 break;297 298 case REGULAR_OPENMODE_APPEND:299 300 handler = fdopen(newDesc, "a");301 302 break;303 304 case REGULAR_OPENMODE_READ_ONLY:305 default:306 307 handler = fdopen(newDesc, "r");308 }309 310 if (handler == NULL)311 {312 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__);313 }314 }315 }316 317 //-------------------------------------------------------------------318 319 void320 regular::close()321 {322 pc::sync::protector pg(keeper);323 324 #ifndef IO_WO_XEXEC325 operType = REGULAR_OPERATION_CLOSE;326 performXExec(preExec);327 #endif328 329 if (handler != NULL)330 {331 if (fclose((FILE *)handler) != 0)332 {333 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path);334 }335 336 handler = NULL;337 }338 339 #ifndef IO_WO_XEXEC340 performXExec(postExec);341 #endif342 }343 344 //-------------------------------------------------------------------345 346 void347 regular::open(const dodoString &a_path,348 short a_mode)349 {350 pc::sync::protector pg(keeper);351 352 #ifndef IO_WO_XEXEC353 operType = REGULAR_OPERATION_OPEN;354 performXExec(preExec);355 #endif356 357 path = a_path;358 mode = a_mode;359 360 if (handler != NULL)361 {362 if (fclose((FILE *)handler) != 0)363 {364 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path);365 }366 367 handler = NULL;368 }369 370 bool exists(false);371 372 if (path.size() == 0)373 {374 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_OPEN, exception::ERRNO_LIBDODO, REGULAREX_WRONGFILENAME, IOFILEREGULAREX_WRONGFILENAME_STR, __LINE__, __FILE__, path);375 }376 else377 {378 struct stat st;379 380 if (::lstat(path.c_str(), &st) == -1)381 {382 if (errno != ENOENT)383 {384 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path);385 }386 }387 else388 {389 exists = true;390 }391 392 if (exists && !S_ISREG(st.st_mode) && !S_ISBLK(st.st_mode))393 {394 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_OPEN, exception::ERRNO_LIBDODO, REGULAREX_WRONGFILENAME, IOFILEREGULAREX_WRONGFILENAME_STR, __LINE__, __FILE__, path);395 }396 397 switch (mode)398 {399 case REGULAR_OPENMODE_READ_WRITE:400 401 handler = fopen(path.c_str(), "r+");402 if (handler == NULL)403 {404 handler = fopen(path.c_str(), "w+");405 }406 407 break;408 409 case REGULAR_OPENMODE_READ_WRITE_TRUNCATE:410 411 handler = fopen(path.c_str(), "w+");412 413 break;414 415 case REGULAR_OPENMODE_APPEND:416 417 handler = fopen(path.c_str(), "a");418 419 break;420 421 case REGULAR_OPENMODE_READ_ONLY:422 default:423 424 handler = fopen(path.c_str(), "r");425 }426 }427 428 if (handler == NULL)429 {430 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path);431 }432 433 if (!exists)434 {435 tools::filesystem::chmod(path, DEFAULT_FILE_PERM);436 }437 438 #ifndef IO_WO_XEXEC439 performXExec(postExec);440 #endif441 }442 443 //-------------------------------------------------------------------444 445 void446 regular::_read(char * const a_data)447 {448 if (handler == NULL)449 {450 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path);451 }452 453 unsigned long pos = blockOffset ? this->pos * inSize : this->pos;454 455 if (fseek((FILE *)handler, pos, SEEK_SET) == -1)456 {457 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path);458 }459 460 memset(a_data, '\0', inSize);461 462 while (true)463 {464 if (fread(a_data, inSize, 1, (FILE *)handler) == 0)465 {466 if (feof((FILE *)handler) != 0 || errno == EAGAIN)467 {468 break;469 49 } 470 50 471 if (errno == EINTR) 472 { 473 continue; 474 } 475 476 if (ferror((FILE *)handler) != 0) 477 { 478 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 479 } 480 } 481 482 break; 483 } 484 } 485 486 //------------------------------------------------------------------- 487 488 void 489 regular::_write(const char *const a_data) 490 { 491 if (handler == NULL) 492 { 493 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 494 } 495 496 if (mode != REGULAR_OPENMODE_APPEND) 497 { 498 if (append) 499 { 500 if (fseek((FILE *)handler, 0, SEEK_END) == -1) 501 { 502 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 503 } 504 } 505 else 506 { 507 unsigned long pos = blockOffset ? this->pos * outSize : this->pos; 508 if (!overwrite) 509 { 510 if (fseek((FILE *)handler, pos, SEEK_SET) == -1) 511 { 512 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 513 } 514 515 char *t_buf = new char[outSize]; 516 517 size_t read = fread(t_buf, outSize, 1, (FILE *)handler); 518 519 delete [] t_buf; 520 521 if (read != 0) 522 { 523 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_LIBDODO, REGULAREX_CANNOTOVEWRITE, IOFILEREGULAREX_CANNOTOVEWRITE_STR, __LINE__, __FILE__, path); 524 } 525 } 526 527 if (fseek((FILE *)handler, pos, SEEK_SET) == -1) 528 { 529 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 530 } 531 } 532 } 533 534 while (true) 535 { 536 if (fwrite(a_data, outSize, 1, (FILE *)handler) == 0) 537 { 538 if (errno == EINTR) 539 { 540 continue; 541 } 542 543 if (errno == EAGAIN) 544 { 545 break; 546 } 547 548 if (ferror((FILE *)handler) != 0) 549 { 550 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 551 } 552 } 553 554 break; 555 } 556 } 557 558 //------------------------------------------------------------------- 559 560 void 561 regular::erase() 562 { 563 pc::sync::protector pg(keeper); 564 565 char *empty = new char[outSize]; 566 567 memset(empty, 0, outSize); 568 569 bool _overwrite = overwrite; 570 overwrite = true; 571 572 try 573 { 574 _write(empty); 575 576 overwrite = _overwrite; 577 } 578 catch (...) 579 { 580 overwrite = _overwrite; 581 582 delete [] empty; 583 584 throw; 585 } 586 587 delete [] empty; 588 } 589 590 //------------------------------------------------------------------- 591 592 void 593 regular::flush() 594 { 595 pc::sync::protector pg(keeper); 596 597 if (handler == NULL) 598 { 599 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_FLUSH, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 600 } 601 602 if (fflush((FILE *)handler) != 0) 603 { 604 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_FLUSH, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 605 } 606 } 607 608 //------------------------------------------------------------------- 609 610 unsigned long 611 regular::_readStream(char * const a_data) 612 { 613 if (handler == NULL) 614 { 615 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 616 } 617 618 unsigned long readSize = inSize + 1; 619 620 if (blockOffset) 621 { 622 if (fseek((FILE *)handler, 0, SEEK_SET) == -1) 623 { 624 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 625 } 626 627 for (unsigned long i = 0; i < pos; ++i) 628 { 629 if (fgets(a_data, readSize, (FILE *)handler) == NULL) 630 { 631 switch (errno) 632 { 633 case EIO: 634 case EINTR: 635 case EBADF: 636 case EOVERFLOW: 637 case ENOMEM: 638 case ENXIO: 639 640 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 641 } 642 643 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_LIBDODO, REGULAREX_FILEISSHORTERTHANGIVENPOSITION, IOFILEREGULAREX_FILEISSHORTERTHANGIVENPOSITION_STR, __LINE__, __FILE__, path); 644 } 645 } 646 } 647 else if (fseek((FILE *)handler, pos, SEEK_SET) == -1) 648 { 649 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 650 } 651 652 memset(a_data, '\0', readSize); 653 654 while (true) 655 { 656 if (fgets(a_data, readSize, (FILE *)handler) == NULL) 657 { 658 if (errno == EINTR) 659 { 660 continue; 661 } 662 663 if (errno == EAGAIN) 664 { 665 break; 666 } 667 668 if (ferror((FILE *)handler) != 0) 669 { 670 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 671 } 672 } 673 674 break; 675 } 676 677 return strlen(a_data); 678 } 679 680 //------------------------------------------------------------------- 681 682 void 683 regular::_writeStream(const char *const a_data) 684 { 685 if (handler == NULL) 686 { 687 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 688 } 689 690 if (mode != REGULAR_OPENMODE_APPEND) 691 { 692 if (fseek((FILE *)handler, 0, SEEK_END) == -1) 693 { 694 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 695 } 696 } 697 698 unsigned int bufSize = strlen(a_data); 699 700 unsigned long _outSize = outSize; 701 702 if (bufSize < _outSize) 703 { 704 _outSize = bufSize; 705 } 706 707 while (true) 708 { 709 if (fwrite(a_data, _outSize, 1, (FILE *)handler) == 0) 710 { 711 if (errno == EINTR) 712 { 713 continue; 714 } 715 716 if (ferror((FILE *)handler) != 0) 717 { 718 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 719 } 720 } 721 722 break; 723 } 724 } 725 726 //------------------------------------------------------------------- 727 51 FILE *file; 52 }; 53 }; 54 }; -
trunk/src/ioFileFifo.cc
r1183 r1190 34 34 #include <sys/stat.h> 35 35 36 #include "ioFile.inline" 37 36 38 #include <libdodo/ioFileFifo.h> 37 39 #include <libdodo/toolsFilesystem.h> … … 46 48 outFileFifoBuffer(IOPIPE_OUTSIZE), 47 49 blocked(true), 48 handle r(NULL),50 handle(new io::__file), 49 51 channel(protection) 50 52 { … … 61 63 outFileFifoBuffer(IOPIPE_OUTSIZE), 62 64 blocked(true), 63 handle r(NULL),65 handle(new io::__file), 64 66 path(path), 65 67 mode(mode), … … 101 103 case FIFO_OPENMODE_WRITE: 102 104 103 handle r= fopen(path.c_str(), "w");105 handle->file = fopen(path.c_str(), "w"); 104 106 105 107 break; … … 126 128 } 127 129 128 handle r= fdopen(fd, "r");130 handle->file = fdopen(fd, "r"); 129 131 130 132 break; … … 134 136 default: 135 137 136 handle r= fopen(path.c_str(), "r");137 } 138 } 139 140 if (handle r== NULL)138 handle->file = fopen(path.c_str(), "r"); 139 } 140 } 141 142 if (handle->file == NULL) 141 143 { 142 144 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_FIFO, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 151 153 mode(fd.mode), 152 154 path(fd.path), 153 handle r(NULL),155 handle(new __file), 154 156 channel(fd.protection) 155 157 { … … 161 163 outSize = fd.outSize; 162 164 163 if (fd.handle r!= NULL)165 if (fd.handle->file != NULL) 164 166 { 165 167 int oldDesc, newDesc; 166 168 167 oldDesc = fileno( (FILE *)fd.handler);169 oldDesc = fileno(fd.handle->file); 168 170 if (oldDesc == -1) 169 171 { … … 181 183 case FIFO_OPENMODE_WRITE: 182 184 183 handle r= fdopen(newDesc, "w");185 handle->file = fdopen(newDesc, "w"); 184 186 185 187 break; … … 188 190 default: 189 191 190 handle r= fdopen(newDesc, "r");191 } 192 193 if (handle r== NULL)192 handle->file = fdopen(newDesc, "r"); 193 } 194 195 if (handle->file == NULL) 194 196 { 195 197 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_FIFO, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 202 204 fifo::~fifo() 203 205 { 204 if (handler != NULL) 205 { 206 fclose((FILE *)handler); 207 } 206 if (handle->file != NULL) 207 { 208 fclose(handle->file); 209 } 210 211 delete handle; 208 212 } 209 213 … … 215 219 pc::sync::protector pg(keeper); 216 220 217 if (handle r== NULL)221 if (handle->file == NULL) 218 222 { 219 223 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_GETINDESCRIPTOR, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 220 224 } 221 225 222 return fileno( (FILE *)handler);226 return fileno(handle->file); 223 227 } 224 228 … … 230 234 pc::sync::protector pg(keeper); 231 235 232 if (handle r== NULL)236 if (handle->file == NULL) 233 237 { 234 238 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_GETOUTDESCRIPTOR, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 235 239 } 236 240 237 return fileno( (FILE *)handler);241 return fileno(handle->file); 238 242 } 239 243 … … 245 249 pc::sync::protector pg(keeper); 246 250 247 if (handle r!= NULL)248 { 249 if (fclose( (FILE *)handler) != 0)251 if (handle->file != NULL) 252 { 253 if (fclose(handle->file) != 0) 250 254 { 251 255 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 252 256 } 253 257 254 handle r= NULL;258 handle->file = NULL; 255 259 } 256 260 … … 263 267 outSize = fd.outSize; 264 268 265 if (fd.handle r!= NULL)269 if (fd.handle->file != NULL) 266 270 { 267 271 int oldDesc, newDesc; 268 272 269 oldDesc = fileno( (FILE *)fd.handler);273 oldDesc = fileno(fd.handle->file); 270 274 if (oldDesc == -1) 271 275 { … … 283 287 case FIFO_OPENMODE_WRITE: 284 288 285 handle r= fdopen(newDesc, "w");289 handle->file = fdopen(newDesc, "w"); 286 290 287 291 break; … … 290 294 default: 291 295 292 handle r= fdopen(newDesc, "r");293 } 294 295 if (handle r== NULL)296 handle->file = fdopen(newDesc, "r"); 297 } 298 299 if (handle->file == NULL) 296 300 { 297 301 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 312 316 #endif 313 317 314 if (handle r!= NULL)315 { 316 if (fclose( (FILE *)handler) != 0)318 if (handle->file != NULL) 319 { 320 if (fclose(handle->file) != 0) 317 321 { 318 322 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 319 323 } 320 324 321 handle r= NULL;325 handle->file = NULL; 322 326 } 323 327 … … 343 347 mode = a_mode; 344 348 345 if (handle r!= NULL)346 { 347 if (fclose( (FILE *)handler) != 0)349 if (handle->file != NULL) 350 { 351 if (fclose(handle->file) != 0) 348 352 { 349 353 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 350 354 } 351 355 352 handle r= NULL;356 handle->file = NULL; 353 357 } 354 358 … … 388 392 case FIFO_OPENMODE_WRITE: 389 393 390 handle r= fopen(path.c_str(), "w");394 handle->file = fopen(path.c_str(), "w"); 391 395 392 396 break; … … 413 417 } 414 418 415 handle r= fdopen(fd, "r");419 handle->file = fdopen(fd, "r"); 416 420 417 421 break; … … 421 425 default: 422 426 423 handle r= fopen(path.c_str(), "r");424 } 425 } 426 427 if (handle r== NULL)427 handle->file = fopen(path.c_str(), "r"); 428 } 429 } 430 431 if (handle->file == NULL) 428 432 { 429 433 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 452 456 pc::sync::protector pg(keeper); 453 457 454 if (handle r== NULL)458 if (handle->file == NULL) 455 459 { 456 460 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_BLOCK, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__); … … 464 468 int blockFlag; 465 469 466 int desc = fileno( (FILE *)handler);470 int desc = fileno(handle->file); 467 471 if (desc == -1) 468 472 { … … 498 502 fifo::_read(char * const a_data) 499 503 { 500 if (handle r== NULL)504 if (handle->file == NULL) 501 505 { 502 506 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__READ, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); … … 519 523 while (true) 520 524 { 521 if ((n = fread(data, 1, batch, (FILE *)handler)) == 0)522 { 523 if (feof( (FILE *)handler) != 0 || errno == EAGAIN)525 if ((n = fread(data, 1, batch, handle->file)) == 0) 526 { 527 if (feof(handle->file) != 0 || errno == EAGAIN) 524 528 { 525 529 break; … … 531 535 } 532 536 533 if (ferror( (FILE *)handler) != 0)537 if (ferror(handle->file) != 0) 534 538 { 535 539 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 552 556 while (true) 553 557 { 554 if ((n = fread(data, 1, batch, (FILE *)handler)) == 0)555 { 556 if (feof( (FILE *)handler) != 0 || errno == EAGAIN)558 if ((n = fread(data, 1, batch, handle->file)) == 0) 559 { 560 if (feof(handle->file) != 0 || errno == EAGAIN) 557 561 { 558 562 break; … … 564 568 } 565 569 566 if (ferror( (FILE *)handler) != 0)570 if (ferror(handle->file) != 0) 567 571 { 568 572 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 584 588 fifo::_write(const char *const a_data) 585 589 { 586 if (handle r== NULL)590 if (handle->file == NULL) 587 591 { 588 592 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__WRITE, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); … … 603 607 while (true) 604 608 { 605 if ((n = fwrite(data, 1, batch, (FILE *)handler)) == 0)609 if ((n = fwrite(data, 1, batch, handle->file)) == 0) 606 610 { 607 611 if (errno == EINTR) … … 615 619 } 616 620 617 if (ferror( (FILE *)handler) != 0)621 if (ferror(handle->file) != 0) 618 622 { 619 623 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 636 640 while (true) 637 641 { 638 if ((n = fwrite(data, 1, batch, (FILE *)handler)) == 0)642 if ((n = fwrite(data, 1, batch, handle->file)) == 0) 639 643 { 640 644 if (errno == EINTR) … … 648 652 } 649 653 650 if (ferror( (FILE *)handler) != 0)654 if (ferror(handle->file) != 0) 651 655 { 652 656 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 670 674 pc::sync::protector pg(keeper); 671 675 672 if (handle r== NULL)676 if (handle->file == NULL) 673 677 { 674 678 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_FLUSH, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); 675 679 } 676 680 677 if (fflush( (FILE *)handler) != 0)681 if (fflush(handle->file) != 0) 678 682 { 679 683 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX_FLUSH, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 686 690 fifo::_readStream(char * const a_data) 687 691 { 688 if (handle r== NULL)692 if (handle->file == NULL) 689 693 { 690 694 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__READSTREAM, exception::ERRNO_LIBDODO, FIFOEX_NOTOPENED, IOFILEFIFOEX_NOTOPENED_STR, __LINE__, __FILE__, path); … … 697 701 while (true) 698 702 { 699 if (fgets(a_data, readSize, (FILE *)handler) == NULL)703 if (fgets(a_data, readSize, handle->file) == NULL) 700 704 { 701 705 if (errno == EINTR) … … 709 713 } 710 714 711 if (ferror( (FILE *)handler) != 0)715 if (ferror(handle->file) != 0) 712 716 { 713 717 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 741 745 while (true) 742 746 { 743 if (fputc('\n', (FILE *)handler) == EOF)747 if (fputc('\n', handle->file) == EOF) 744 748 { 745 749 if (errno == EINTR) … … 753 757 } 754 758 755 if (ferror( (FILE *)handler) != 0)759 if (ferror(handle->file) != 0) 756 760 { 757 761 throw exception::basic(exception::ERRMODULE_IOFILEFIFO, FIFOEX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); -
trunk/src/ioFileRegular.cc
r1183 r1190 35 35 #include <sys/stat.h> 36 36 37 #include "ioFile.inline" 38 37 39 #include <libdodo/ioFileRegular.h> 38 40 #include <libdodo/toolsFilesystem.h> … … 48 50 blockOffset(true), 49 51 append(false), 50 handle r(NULL),52 handle(new io::__file), 51 53 channel(protection) 52 54 { … … 64 66 blockOffset(true), 65 67 append(false), 66 handle r(NULL),68 handle(new io::__file), 67 69 path(a_path), 68 70 mode(a_mode), … … 104 106 case REGULAR_OPENMODE_READ_WRITE: 105 107 106 handle r= fopen(path.c_str(), "r+");107 if (handle r== NULL)108 handle->file = fopen(path.c_str(), "r+"); 109 if (handle->file == NULL) 108 110 { 109 handle r= fopen(path.c_str(), "w+");111 handle->file = fopen(path.c_str(), "w+"); 110 112 } 111 113 … … 114 116 case REGULAR_OPENMODE_READ_WRITE_TRUNCATE: 115 117 116 handle r= fopen(path.c_str(), "w+");118 handle->file = fopen(path.c_str(), "w+"); 117 119 118 120 break; … … 120 122 case REGULAR_OPENMODE_APPEND: 121 123 122 handle r= fopen(path.c_str(), "a");124 handle->file = fopen(path.c_str(), "a"); 123 125 124 126 break; … … 127 129 default: 128 130 129 handle r= fopen(path.c_str(), "r");130 } 131 } 132 133 if (handle r== NULL)131 handle->file = fopen(path.c_str(), "r"); 132 } 133 } 134 135 if (handle->file == NULL) 134 136 { 135 137 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 150 152 append(fd.append), 151 153 mode(fd.mode), 152 handle r(NULL),154 handle(new io::__file), 153 155 channel(fd.protection) 154 156 … … 161 163 outSize = fd.outSize; 162 164 163 if (fd.handle r!= NULL)165 if (fd.handle->file != NULL) 164 166 { 165 167 int oldDesc, newDesc; 166 168 167 oldDesc = fileno( (FILE *)fd.handler);169 oldDesc = fileno(fd.handle->file); 168 170 if (oldDesc == -1) 169 171 { … … 182 184 case REGULAR_OPENMODE_READ_WRITE_TRUNCATE: 183 185 184 handle r= fdopen(newDesc, "r+");186 handle->file = fdopen(newDesc, "r+"); 185 187 186 188 break; … … 188 190 case REGULAR_OPENMODE_APPEND: 189 191 190 handle r= fdopen(newDesc, "a");192 handle->file = fdopen(newDesc, "a"); 191 193 192 194 break; … … 195 197 default: 196 198 197 handle r= fdopen(newDesc, "r");198 } 199 200 if (handle r== NULL)199 handle->file = fdopen(newDesc, "r"); 200 } 201 202 if (handle->file == NULL) 201 203 { 202 204 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_REGULAR, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 209 211 regular::~regular() 210 212 { 211 if (handler != NULL) 212 { 213 fclose((FILE *)handler); 214 } 213 if (handle->file != NULL) 214 { 215 fclose(handle->file); 216 } 217 218 delete handle; 215 219 } 216 220 … … 222 226 pc::sync::protector pg(keeper); 223 227 224 if (handle r== NULL)228 if (handle->file == NULL) 225 229 { 226 230 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_GETINDESCRIPTOR, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 227 231 } 228 232 229 return fileno( (FILE *)handler);233 return fileno(handle->file); 230 234 } 231 235 … … 237 241 pc::sync::protector pg(keeper); 238 242 239 if (handle r== NULL)243 if (handle->file == NULL) 240 244 { 241 245 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_GETOUTDESCRIPTOR, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 242 246 } 243 247 244 return fileno( (FILE *)handler);248 return fileno(handle->file); 245 249 } 246 250 … … 252 256 pc::sync::protector pg(keeper); 253 257 254 if (handle r!= NULL)255 { 256 if (fclose( (FILE *)handler) != 0)258 if (handle->file != NULL) 259 { 260 if (fclose(handle->file) != 0) 257 261 { 258 262 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 259 263 } 260 264 261 handle r= NULL;265 handle->file = NULL; 262 266 } 263 267 … … 271 275 outSize = fd.outSize; 272 276 273 if (fd.handle r!= NULL)277 if (fd.handle->file != NULL) 274 278 { 275 279 int oldDesc, newDesc; 276 280 277 oldDesc = fileno( (FILE *)fd.handler);281 oldDesc = fileno(fd.handle->file); 278 282 if (oldDesc == -1) 279 283 { … … 292 296 case REGULAR_OPENMODE_READ_WRITE_TRUNCATE: 293 297 294 handle r= fdopen(newDesc, "r+");298 handle->file = fdopen(newDesc, "r+"); 295 299 296 300 break; … … 298 302 case REGULAR_OPENMODE_APPEND: 299 303 300 handle r= fdopen(newDesc, "a");304 handle->file = fdopen(newDesc, "a"); 301 305 302 306 break; … … 305 309 default: 306 310 307 handle r= fdopen(newDesc, "r");308 } 309 310 if (handle r== NULL)311 handle->file = fdopen(newDesc, "r"); 312 } 313 314 if (handle->file == NULL) 311 315 { 312 316 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 327 331 #endif 328 332 329 if (handle r!= NULL)330 { 331 if (fclose( (FILE *)handler) != 0)333 if (handle->file != NULL) 334 { 335 if (fclose(handle->file) != 0) 332 336 { 333 337 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 334 338 } 335 339 336 handle r= NULL;340 handle->file = NULL; 337 341 } 338 342 … … 358 362 mode = a_mode; 359 363 360 if (handle r!= NULL)361 { 362 if (fclose( (FILE *)handler) != 0)364 if (handle->file != NULL) 365 { 366 if (fclose(handle->file) != 0) 363 367 { 364 368 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); 365 369 } 366 370 367 handle r= NULL;371 handle->file = NULL; 368 372 } 369 373 … … 399 403 case REGULAR_OPENMODE_READ_WRITE: 400 404 401 handle r= fopen(path.c_str(), "r+");402 if (handle r== NULL)405 handle->file = fopen(path.c_str(), "r+"); 406 if (handle->file == NULL) 403 407 { 404 handle r= fopen(path.c_str(), "w+");408 handle->file = fopen(path.c_str(), "w+"); 405 409 } 406 410 … … 409 413 case REGULAR_OPENMODE_READ_WRITE_TRUNCATE: 410 414 411 handle r= fopen(path.c_str(), "w+");415 handle->file = fopen(path.c_str(), "w+"); 412 416 413 417 break; … … 415 419 case REGULAR_OPENMODE_APPEND: 416 420 417 handle r= fopen(path.c_str(), "a");421 handle->file = fopen(path.c_str(), "a"); 418 422 419 423 break; … … 422 426 default: 423 427 424 handle r= fopen(path.c_str(), "r");425 } 426 } 427 428 if (handle r== NULL)428 handle->file = fopen(path.c_str(), "r"); 429 } 430 } 431 432 if (handle->file == NULL) 429 433 { 430 434 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 446 450 regular::_read(char * const a_data) 447 451 { 448 if (handle r== NULL)452 if (handle->file == NULL) 449 453 { 450 454 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); … … 453 457 unsigned long pos = blockOffset ? this->pos * inSize : this->pos; 454 458 455 if (fseek( (FILE *)handler, pos, SEEK_SET) == -1)459 if (fseek(handle->file, pos, SEEK_SET) == -1) 456 460 { 457 461 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 462 466 while (true) 463 467 { 464 if (fread(a_data, inSize, 1, (FILE *)handler) == 0)465 { 466 if (feof( (FILE *)handler) != 0 || errno == EAGAIN)468 if (fread(a_data, inSize, 1, handle->file) == 0) 469 { 470 if (feof(handle->file) != 0 || errno == EAGAIN) 467 471 { 468 472 break; … … 474 478 } 475 479 476 if (ferror( (FILE *)handler) != 0)480 if (ferror(handle->file) != 0) 477 481 { 478 482 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 489 493 regular::_write(const char *const a_data) 490 494 { 491 if (handle r== NULL)495 if (handle->file == NULL) 492 496 { 493 497 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); … … 498 502 if (append) 499 503 { 500 if (fseek( (FILE *)handler, 0, SEEK_END) == -1)504 if (fseek(handle->file, 0, SEEK_END) == -1) 501 505 { 502 506 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 508 512 if (!overwrite) 509 513 { 510 if (fseek( (FILE *)handler, pos, SEEK_SET) == -1)514 if (fseek(handle->file, pos, SEEK_SET) == -1) 511 515 { 512 516 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 515 519 char *t_buf = new char[outSize]; 516 520 517 size_t read = fread(t_buf, outSize, 1, (FILE *)handler);521 size_t read = fread(t_buf, outSize, 1, handle->file); 518 522 519 523 delete [] t_buf; … … 525 529 } 526 530 527 if (fseek( (FILE *)handler, pos, SEEK_SET) == -1)531 if (fseek(handle->file, pos, SEEK_SET) == -1) 528 532 { 529 533 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 534 538 while (true) 535 539 { 536 if (fwrite(a_data, outSize, 1, (FILE *)handler) == 0)540 if (fwrite(a_data, outSize, 1, handle->file) == 0) 537 541 { 538 542 if (errno == EINTR) … … 546 550 } 547 551 548 if (ferror( (FILE *)handler) != 0)552 if (ferror(handle->file) != 0) 549 553 { 550 554 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 595 599 pc::sync::protector pg(keeper); 596 600 597 if (handle r== NULL)601 if (handle->file == NULL) 598 602 { 599 603 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_FLUSH, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); 600 604 } 601 605 602 if (fflush( (FILE *)handler) != 0)606 if (fflush(handle->file) != 0) 603 607 { 604 608 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX_FLUSH, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 611 615 regular::_readStream(char * const a_data) 612 616 { 613 if (handle r== NULL)617 if (handle->file == NULL) 614 618 { 615 619 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); … … 620 624 if (blockOffset) 621 625 { 622 if (fseek( (FILE *)handler, 0, SEEK_SET) == -1)626 if (fseek(handle->file, 0, SEEK_SET) == -1) 623 627 { 624 628 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 627 631 for (unsigned long i = 0; i < pos; ++i) 628 632 { 629 if (fgets(a_data, readSize, (FILE *)handler) == NULL)633 if (fgets(a_data, readSize, handle->file) == NULL) 630 634 { 631 635 switch (errno) … … 645 649 } 646 650 } 647 else if (fseek( (FILE *)handler, pos, SEEK_SET) == -1)651 else if (fseek(handle->file, pos, SEEK_SET) == -1) 648 652 { 649 653 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 654 658 while (true) 655 659 { 656 if (fgets(a_data, readSize, (FILE *)handler) == NULL)660 if (fgets(a_data, readSize, handle->file) == NULL) 657 661 { 658 662 if (errno == EINTR) … … 666 670 } 667 671 668 if (ferror( (FILE *)handler) != 0)672 if (ferror(handle->file) != 0) 669 673 { 670 674 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 683 687 regular::_writeStream(const char *const a_data) 684 688 { 685 if (handle r== NULL)689 if (handle->file == NULL) 686 690 { 687 691 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_LIBDODO, REGULAREX_NOTOPENED, IOFILEREGULAREX_NOTOPENED_STR, __LINE__, __FILE__, path); … … 690 694 if (mode != REGULAR_OPENMODE_APPEND) 691 695 { 692 if (fseek( (FILE *)handler, 0, SEEK_END) == -1)696 if (fseek(handle->file, 0, SEEK_END) == -1) 693 697 { 694 698 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__, path); … … 707 711 while (true) 708 712 { 709 if (fwrite(a_data, _outSize, 1, (FILE *)handler) == 0)713 if (fwrite(a_data, _outSize, 1, handle->file) == 0) 710 714 { 711 715 if (errno == EINTR) … … 714 718 } 715 719 716 if (ferror( (FILE *)handler) != 0)720 if (ferror(handle->file) != 0) 717 721 { 718 722 throw exception::basic(exception::ERRMODULE_IOFILEREGULAR, REGULAREX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); -
trunk/src/ioFileTemp.cc
r1183 r1190 34 34 #include <sys/stat.h> 35 35 36 #include "ioFile.inline" 37 36 38 #include <libdodo/ioFileTemp.h> 37 39 #include <libdodo/ioFileTempEx.h> … … 47 49 blockOffset(true), 48 50 append(false), 49 handle r(NULL),51 handle(new io::__file), 50 52 channel(protection) 51 53 { … … 56 58 if (open) 57 59 { 58 handle r= tmpfile();59 if (handle r== NULL)60 handle->file = tmpfile(); 61 if (handle->file == NULL) 60 62 { 61 63 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_TEMP, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 70 72 blockOffset(fd.blockOffset), 71 73 append(fd.append), 72 handle r(NULL),74 handle(new io::__file), 73 75 channel(protection) 74 76 … … 81 83 outSize = fd.outSize; 82 84 83 if (fd.handle r!= NULL)85 if (fd.handle->file != NULL) 84 86 { 85 87 int oldDesc, newDesc; 86 88 87 oldDesc = fileno( (FILE *)fd.handler);89 oldDesc = fileno(fd.handle->file); 88 90 if (oldDesc == -1) 89 91 { … … 97 99 } 98 100 99 handle r= fdopen(newDesc, "r+");100 101 if (handle r== NULL)101 handle->file = fdopen(newDesc, "r+"); 102 103 if (handle->file == NULL) 102 104 { 103 105 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_TEMP, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 110 112 temp::~temp() 111 113 { 112 if (handler != NULL) 113 { 114 fclose((FILE *)handler); 115 } 114 if (handle->file != NULL) 115 { 116 fclose(handle->file); 117 } 118 119 delete handle; 116 120 } 117 121 … … 123 127 pc::sync::protector pg(keeper); 124 128 125 if (handle r== NULL)129 if (handle->file == NULL) 126 130 { 127 131 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_GETINDESCRIPTOR, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 128 132 } 129 133 130 return fileno( (FILE *)handler);134 return fileno(handle->file); 131 135 } 132 136 … … 138 142 pc::sync::protector pg(keeper); 139 143 140 if (handle r== NULL)144 if (handle->file == NULL) 141 145 { 142 146 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_GETOUTDESCRIPTOR, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 143 147 } 144 148 145 return fileno( (FILE *)handler);149 return fileno(handle->file); 146 150 } 147 151 … … 153 157 pc::sync::protector pg(keeper); 154 158 155 if (handle r!= NULL)156 { 157 if (fclose( (FILE *)handler) != 0)159 if (handle->file != NULL) 160 { 161 if (fclose(handle->file) != 0) 158 162 { 159 163 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 160 164 } 161 165 162 handle r= NULL;166 handle->file = NULL; 163 167 } 164 168 … … 170 174 outSize = fd.outSize; 171 175 172 if (fd.handle r!= NULL)176 if (fd.handle->file != NULL) 173 177 { 174 178 int oldDesc, newDesc; 175 179 176 oldDesc = fileno( (FILE *)fd.handler);180 oldDesc = fileno(fd.handle->file); 177 181 if (oldDesc == -1) 178 182 { … … 186 190 } 187 191 188 handle r= fdopen(newDesc, "r+");189 190 if (handle r== NULL)192 handle->file = fdopen(newDesc, "r+"); 193 194 if (handle->file == NULL) 191 195 { 192 196 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 207 211 #endif 208 212 209 if (handle r!= NULL)210 { 211 if (fclose( (FILE *)handler) != 0)213 if (handle->file != NULL) 214 { 215 if (fclose(handle->file) != 0) 212 216 { 213 217 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 214 218 } 215 219 216 handle r= NULL;220 handle->file = NULL; 217 221 } 218 222 … … 234 238 #endif 235 239 236 if (handle r!= NULL)237 { 238 if (fclose( (FILE *)handler) != 0)240 if (handle->file != NULL) 241 { 242 if (fclose(handle->file) != 0) 239 243 { 240 244 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 241 245 } 242 246 243 handle r= NULL;244 } 245 246 handle r= tmpfile();247 if (handle r== NULL)247 handle->file = NULL; 248 } 249 250 handle->file = tmpfile(); 251 if (handle->file == NULL) 248 252 { 249 253 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 260 264 temp::_read(char * const a_data) 261 265 { 262 if (handle r== NULL)266 if (handle->file == NULL) 263 267 { 264 268 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__READ, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); … … 267 271 unsigned long pos = blockOffset ? this->pos * inSize : this->pos; 268 272 269 if (fseek( (FILE *)handler, pos * inSize, SEEK_SET) == -1)273 if (fseek(handle->file, pos * inSize, SEEK_SET) == -1) 270 274 { 271 275 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 276 280 while (true) 277 281 { 278 if (fread(a_data, inSize, 1, (FILE *)handler) == 0)279 { 280 if (feof( (FILE *)handler) != 0 || errno == EAGAIN)282 if (fread(a_data, inSize, 1, handle->file) == 0) 283 { 284 if (feof(handle->file) != 0 || errno == EAGAIN) 281 285 { 282 286 break; … … 288 292 } 289 293 290 if (ferror( (FILE *)handler) != 0)294 if (ferror(handle->file) != 0) 291 295 { 292 296 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 303 307 temp::_write(const char *const a_data) 304 308 { 305 if (handle r== NULL)309 if (handle->file == NULL) 306 310 { 307 311 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); … … 310 314 if (append) 311 315 { 312 if (fseek( (FILE *)handler, 0, SEEK_END) == -1)316 if (fseek(handle->file, 0, SEEK_END) == -1) 313 317 { 314 318 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 320 324 if (!overwrite) 321 325 { 322 if (fseek( (FILE *)handler, pos, SEEK_SET) == -1)326 if (fseek(handle->file, pos, SEEK_SET) == -1) 323 327 { 324 328 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 327 331 char *t_buf = new char[outSize]; 328 332 329 size_t read = fread(t_buf, outSize, 1, (FILE *)handler);333 size_t read = fread(t_buf, outSize, 1, handle->file); 330 334 331 335 delete [] t_buf; … … 337 341 } 338 342 339 if (fseek( (FILE *)handler, pos, SEEK_SET) == -1)343 if (fseek(handle->file, pos, SEEK_SET) == -1) 340 344 { 341 345 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 345 349 while (true) 346 350 { 347 if (fwrite(a_data, outSize, 1, (FILE *)handler) == 0)351 if (fwrite(a_data, outSize, 1, handle->file) == 0) 348 352 { 349 353 if (errno == EINTR) … … 357 361 } 358 362 359 if (ferror( (FILE *)handler) != 0)363 if (ferror(handle->file) != 0) 360 364 { 361 365 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__WRITE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 406 410 pc::sync::protector pg(keeper); 407 411 408 if (handle r== NULL)412 if (handle->file == NULL) 409 413 { 410 414 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_FLUSH, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 411 415 } 412 416 413 if (fflush( (FILE *)handler) != 0)417 if (fflush(handle->file) != 0) 414 418 { 415 419 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX_FLUSH, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 422 426 temp::_readStream(char * const a_data) 423 427 { 424 if (handle r== NULL)428 if (handle->file == NULL) 425 429 { 426 430 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); … … 431 435 if (blockOffset) 432 436 { 433 if (fseek( (FILE *)handler, 0, SEEK_SET) == -1)437 if (fseek(handle->file, 0, SEEK_SET) == -1) 434 438 { 435 439 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 438 442 for (unsigned long i = 0; i < pos; ++i) 439 443 { 440 if (fgets(a_data, readSize, (FILE *)handler) == NULL)444 if (fgets(a_data, readSize, handle->file) == NULL) 441 445 { 442 446 switch (errno) … … 456 460 } 457 461 } 458 else if (fseek( (FILE *)handler, pos, SEEK_SET) == -1)462 else if (fseek(handle->file, pos, SEEK_SET) == -1) 459 463 { 460 464 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 465 469 while (true) 466 470 { 467 if (fgets(a_data, readSize, (FILE *)handler) == NULL)471 if (fgets(a_data, readSize, handle->file) == NULL) 468 472 { 469 473 if (errno == EINTR) … … 477 481 } 478 482 479 if (ferror( (FILE *)handler) != 0)483 if (ferror(handle->file) != 0) 480 484 { 481 485 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__READSTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 494 498 temp::_writeStream(const char *const a_data) 495 499 { 496 if (handle r== NULL)500 if (handle->file == NULL) 497 501 { 498 502 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__WRITESTREAM, exception::ERRNO_LIBDODO, TEMPEX_NOTOPENED, IOFILETEMPEX_NOTOPENED_STR, __LINE__, __FILE__); 499 503 } 500 504 501 if (fseek( (FILE *)handler, 0, SEEK_END) == -1)505 if (fseek(handle->file, 0, SEEK_END) == -1) 502 506 { 503 507 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 515 519 while (true) 516 520 { 517 if (fwrite(a_data, _outSize, 1, (FILE *)handler) == 0)521 if (fwrite(a_data, _outSize, 1, handle->file) == 0) 518 522 { 519 523 if (errno == EINTR) … … 522 526 } 523 527 524 if (ferror( (FILE *)handler) != 0)528 if (ferror(handle->file) != 0) 525 529 { 526 530 throw exception::basic(exception::ERRMODULE_IOFILETEMP, TEMPEX__WRITESTREAM, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); -
trunk/src/ioPipe.cc
r1189 r1190 34 34 #include <fcntl.h> 35 35 36 #include "ioFile.inline" 37 36 38 #include <libdodo/ioPipe.h> 37 39 #include <libdodo/ioPipeEx.h> … … 46 48 outPipeBuffer(IOPIPE_OUTSIZE), 47 49 blocked(true), 48 in( NULL),49 out( NULL),50 in(new io::__file), 51 out(new io::__file), 50 52 channel(protection) 51 53 { … … 63 65 } 64 66 65 in = fdopen(pipefd[0], "r");66 if (in == NULL)67 { 68 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_PIPE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 69 } 70 71 out = fdopen(pipefd[1], "w");72 if (out == NULL)67 in->file = fdopen(pipefd[0], "r"); 68 if (in->file == NULL) 69 { 70 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_PIPE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 71 } 72 73 out->file = fdopen(pipefd[1], "w"); 74 if (out->file == NULL) 73 75 { 74 76 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_PIPE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 82 84 outPipeBuffer(fd.outPipeBuffer), 83 85 blocked(fd.blocked), 84 in( NULL),85 out( NULL),86 in(new io::__file), 87 out(new io::__file), 86 88 channel(protection) 87 89 { … … 93 95 outSize = fd.outSize; 94 96 95 if (fd.in != NULL && fd.out!= NULL)97 if (fd.in->file != NULL && fd.out->file != NULL) 96 98 { 97 99 int oldDesc, newDesc; 98 100 99 oldDesc = fileno( (FILE *)fd.in);101 oldDesc = fileno(fd.in->file); 100 102 if (oldDesc == -1) 101 103 { … … 109 111 } 110 112 111 in = fdopen(newDesc, "r");112 if (in == NULL)113 { 114 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_PIPE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 115 } 116 117 oldDesc = fileno( (FILE *)fd.out);113 in->file = fdopen(newDesc, "r"); 114 if (in->file == NULL) 115 { 116 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_PIPE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 117 } 118 119 oldDesc = fileno(fd.out->file); 118 120 if (oldDesc == -1) 119 121 { … … 127 129 } 128 130 129 out = fdopen(newDesc, "w");130 if (out == NULL)131 out->file = fdopen(newDesc, "w"); 132 if (out->file == NULL) 131 133 { 132 134 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_PIPE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 139 141 io::pipe::~pipe() 140 142 { 141 if (in != NULL) 142 { 143 fclose((FILE *)in); 144 } 145 146 if (out != NULL) 147 { 148 fclose((FILE *)out); 149 } 143 if (in->file != NULL) 144 { 145 fclose(in->file); 146 } 147 148 if (out->file != NULL) 149 { 150 fclose(out->file); 151 } 152 153 delete in; 154 delete out; 150 155 } 151 156 … … 157 162 pc::sync::protector pg(keeper); 158 163 159 if (in != NULL)160 { 161 if (fclose( (FILE *)in) != 0)164 if (in->file != NULL) 165 { 166 if (fclose(in->file) != 0) 162 167 { 163 168 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 164 169 } 165 170 166 in = NULL;167 } 168 169 if (out != NULL)170 { 171 if (fclose( (FILE *)out) != 0)171 in->file = NULL; 172 } 173 174 if (out->file != NULL) 175 { 176 if (fclose(out->file) != 0) 172 177 { 173 178 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 174 179 } 175 180 176 out = NULL;181 out->file = NULL; 177 182 } 178 183 … … 183 188 outSize = fd.outSize; 184 189 185 if (fd.in != NULL && fd.out!= NULL)190 if (fd.in->file != NULL && fd.out->file != NULL) 186 191 { 187 192 int oldDesc, newDesc; 188 193 189 oldDesc = fileno( (FILE *)fd.in);194 oldDesc = fileno(fd.in->file); 190 195 if (oldDesc == -1) 191 196 { … … 199 204 } 200 205 201 in = fdopen(newDesc, "r");202 if (in == NULL)206 in->file = fdopen(newDesc, "r"); 207 if (in->file == NULL) 203 208 { 204 209 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 205 210 } 206 211 207 oldDesc = fileno( (FILE *)fd.out);212 oldDesc = fileno(fd.out->file); 208 213 if (oldDesc == -1) 209 214 { … … 217 222 } 218 223 219 out = fdopen(newDesc, "w");220 if (out == NULL)224 out->file = fdopen(newDesc, "w"); 225 if (out->file == NULL) 221 226 { 222 227 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_CLONE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 232 237 pc::sync::protector pg(keeper); 233 238 234 if (in == NULL)239 if (in->file == NULL) 235 240 { 236 241 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_GETINDESCRIPTOR, exception::ERRNO_LIBDODO, PIPEEX_PIPENOTOPENED, IOPIPEEX_NOTOPENED_STR, __LINE__, __FILE__); 237 242 } 238 243 239 return fileno( (FILE *)in);244 return fileno(in->file); 240 245 } 241 246 … … 247 252 pc::sync::protector pg(keeper); 248 253 249 if (out == NULL)254 if (out->file == NULL) 250 255 { 251 256 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_GETOUTDESCRIPTOR, exception::ERRNO_LIBDODO, PIPEEX_PIPENOTOPENED, IOPIPEEX_NOTOPENED_STR, __LINE__, __FILE__); 252 257 } 253 258 254 return fileno( (FILE *)out);259 return fileno(out->file); 255 260 } 256 261 … … 267 272 #endif 268 273 269 if (in != NULL)270 { 271 if (fclose( (FILE *)in) != 0)274 if (in->file != NULL) 275 { 276 if (fclose(in->file) != 0) 272 277 { 273 278 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 274 279 } 275 280 276 in = NULL;277 } 278 279 if (out != NULL)280 { 281 if (fclose( (FILE *)out) != 0)281 in->file = NULL; 282 } 283 284 if (out->file != NULL) 285 { 286 if (fclose(out->file) != 0) 282 287 { 283 288 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_CLOSE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 284 289 } 285 290 286 out = NULL;291 out->file = NULL; 287 292 } 288 293 … … 304 309 #endif 305 310 306 if (in != NULL)307 { 308 if (fclose( (FILE *)in) != 0)311 if (in->file != NULL) 312 { 313 if (fclose(in->file) != 0) 309 314 { 310 315 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 311 316 } 312 317 313 in = NULL;314 } 315 316 if (out != NULL)317 { 318 if (fclose( (FILE *)out) != 0)318 in->file = NULL; 319 } 320 321 if (out->file != NULL) 322 { 323 if (fclose(out->file) != 0) 319 324 { 320 325 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 321 326 } 322 327 323 out = NULL;328 out->file = NULL; 324 329 } 325 330 … … 331 336 } 332 337 333 in = fdopen(pipefd[0], "r");334 if (in == NULL)338 in->file = fdopen(pipefd[0], "r"); 339 if (in->file == NULL) 335 340 { 336 341 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 337 342 } 338 343 339 out = fdopen(pipefd[1], "w");340 if (out == NULL)344 out->file = fdopen(pipefd[1], "w"); 345 if (out->file == NULL) 341 346 { 342 347 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX_OPEN, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 353 358 io::pipe::_read(char * const a_data) 354 359 { 355 if (in == NULL)360 if (in->file == NULL) 356 361 { 357 362 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX__READ, exception::ERRNO_LIBDODO, PIPEEX_PIPENOTOPENED, IOPIPEEX_NOTOPENED_STR, __LINE__, __FILE__); … … 374 379 while (true) 375 380 { 376 if ((n = fread(data, 1, batch, (FILE *)in)) == 0)381 if ((n = fread(data, 1, batch, in->file)) == 0) 377 382 { 378 if (feof( (FILE *)in) != 0 || errno == EAGAIN)383 if (feof(in->file) != 0 || errno == EAGAIN) 379 384 { 380 385 break; … … 386 391 } 387 392 388 if (ferror( (FILE *)in) != 0)393 if (ferror(in->file) != 0) 389 394 { 390 395 throw exception::basic(exception::ERRMODULE_IOPIPE, PIPEEX__READ, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); … … 407 412 while (true) 408 413 { 409 if ((n = fread(data, 1, batch, (FILE *)in)) == 0)414 if ((n = fread(data, 1, batch, in->file)) == 0) 410 415 { 411 if (feof( (FILE *)in) != 0 || errno == EAGAIN)416 if (feof(in->file) != 0 || errno == EAGAIN) 412 417 &nb
