1 #define _XOPEN_SOURCE 700
4 /*#include <locale.h>*/
10 #include <sys/types.h>
17 char credentials_file
[] = "../test_credentials";
19 static int read_config(char **line
, int order
) {
28 file
= fopen(credentials_file
, "r");
30 fprintf(stderr
, "Could open %s\n", credentials_file
);
34 for (int i
= 0; i
< order
; i
++) {
35 if (-1 == getline(line
, &length
, file
)) {
36 fprintf(stderr
, "Could not read line #%d from %s: ",
37 i
+ 1, credentials_file
);
39 fprintf(stderr
, "error occured\n");
41 fprintf(stderr
, "end of file reached\n");
43 fprintf(stderr
, "I don't know why\n");
53 eol
= strpbrk(*line
, "\r\n");
59 const char *username(void) {
60 static char *username
;
63 username
= getenv("ISDS_USERNAME");
65 read_config(&username
, 1);
70 const char *password(void) {
71 static char *password
;
74 password
= getenv("ISDS_PASSWORD");
76 read_config(&password
, 2);
81 void print_DbState(const long int state
) {
83 case DBSTATE_ACCESSIBLE
: printf("ACCESSIBLE\n"); break;
84 case DBSTATE_TEMP_UNACCESSIBLE
: printf("TEMP_UNACCESSIBLE\n"); break;
85 case DBSTATE_NOT_YET_ACCESSIBLE
: printf("NOT_YET_ACCESSIBLE\n"); break;
86 case DBSTATE_PERM_UNACCESSIBLE
: printf("PERM_UNACCESSIBLE\n"); break;
87 case DBSTATE_REMOVED
: printf("REMOVED\n"); break;
88 case DBSTATE_TEMP_UNACCESSIBLE_LAW
: printf("DBSTATE_TEMP_UNACCESSIBLE_LAW"); break;
89 default: printf("<unknown state %ld>\n", state
);
93 void print_DbType(const long int *type
) {
94 if (!type
) printf("NULL\n");
97 case DBTYPE_SYSTEM
: printf("SYSTEM\n"); break;
98 case DBTYPE_FO
: printf("FO\n"); break;
99 case DBTYPE_PFO
: printf("PFO\n"); break;
100 case DBTYPE_PFO_ADVOK
: printf("PFO_ADVOK\n"); break;
101 case DBTYPE_PFO_DANPOR
: printf("PFO_DAPOR\n"); break;
102 case DBTYPE_PFO_INSSPR
: printf("PFO_INSSPR\n"); break;
103 case DBTYPE_PO
: printf("PO\n"); break;
104 case DBTYPE_PO_ZAK
: printf("PO_ZAK\n"); break;
105 case DBTYPE_PO_REQ
: printf("PO_REQ\n"); break;
106 case DBTYPE_OVM
: printf("OVM\n"); break;
107 case DBTYPE_OVM_NOTAR
: printf("OVM_NOTAR\n"); break;
108 case DBTYPE_OVM_EXEKUT
: printf("OVM_EXEKUT\n"); break;
109 case DBTYPE_OVM_REQ
: printf("OVM_REQ\n"); break;
110 default: printf("<unknown type %ld>\n", *type
);
115 void print_UserType(const long int *type
) {
116 if (!type
) printf("NULL\n");
119 case USERTYPE_PRIMARY
: printf("PRIMARY\n"); break;
120 case USERTYPE_ENTRUSTED
: printf("ENTRUSTED\n"); break;
121 case USERTYPE_ADMINISTRATOR
: printf("ADMINISTRATOR\n"); break;
122 case USERTYPE_OFFICIAL
: printf("OFFICIAL\n"); break;
123 default: printf("<unknown type %ld>\n", *type
);
128 void print_sender_type(const isds_sender_type
*type
) {
129 if (!type
) printf("NULL\n");
132 case SENDERTYPE_PRIMARY
: printf("PRIMARY\n"); break;
133 case SENDERTYPE_ENTRUSTED
: printf("ENTRUSTED\n"); break;
134 case SENDERTYPE_ADMINISTRATOR
: printf("ADMINISTRATOR\n"); break;
135 case SENDERTYPE_OFFICIAL
: printf("OFFICIAL\n"); break;
136 case SENDERTYPE_VIRTUAL
: printf("VIRTUAL\n"); break;
137 default: printf("<unknown type %u>\n", *type
);
142 void print_UserPrivils(const long int *privils
) {
144 const char *priviledges
[] = {
154 const int priviledges_count
= sizeof(priviledges
)/sizeof(priviledges
[0]);
156 if (!privils
) printf("NULL\n");
158 printf("%ld (", *privils
);
160 for (int i
= 0; i
< priviledges_count
; i
++) {
161 if (*privils
& (1<<i
)) {
163 ((i
+ 1) == priviledges_count
) ? "%s" : "%s|",
173 void print_hash(const struct isds_hash
*hash
) {
179 switch(hash
->algorithm
) {
180 case HASH_ALGORITHM_MD5
: printf("MD5 "); break;
181 case HASH_ALGORITHM_SHA_1
: printf("SHA-1 "); break;
182 case HASH_ALGORITHM_SHA_256
: printf("SHA-256 "); break;
183 case HASH_ALGORITHM_SHA_512
: printf("SHA-512 "); break;
184 default: printf("<Unknown hash algorithm %d> ", hash
->algorithm
);
188 if (!hash
->value
) printf("<NULL>");
190 for (size_t i
= 0; i
< hash
->length
; i
++) {
191 if (i
> 0) printf(":");
192 printf("%02x", ((uint8_t *)(hash
->value
))[i
]);
199 void print_raw_type(const isds_raw_type type
) {
201 case RAWTYPE_INCOMING_MESSAGE
:
202 printf("INCOMING_MESSAGE\n"); break;
203 case RAWTYPE_PLAIN_SIGNED_INCOMING_MESSAGE
:
204 printf("PLAIN_SIGNED_INCOMING_MESSAGE\n"); break;
205 case RAWTYPE_CMS_SIGNED_INCOMING_MESSAGE
:
206 printf("CMS_SIGNED_INCOMING_MESSAGE\n"); break;
207 case RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE
:
208 printf("PLAIN_SIGNED_OUTGOING_MESSAGE\n"); break;
209 case RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE
:
210 printf("CMS_SIGNED_OUTGOING_MESSAGE\n"); break;
211 case RAWTYPE_DELIVERYINFO
:
212 printf("DELIVERYINFO\n"); break;
213 case RAWTYPE_PLAIN_SIGNED_DELIVERYINFO
:
214 printf("PLAIN_SIGNED_DELIVERYINFO\n"); break;
215 case RAWTYPE_CMS_SIGNED_DELIVERYINFO
:
216 printf("CMS_SIGNED_DELIVERYINFO\n"); break;
218 printf("<Unknown raw type %d> ", type
);
223 static void print_dmMessageStatus(const isds_message_status
*status
) {
224 if (!status
) printf("NULL\n");
227 case MESSAGESTATE_SENT
: printf("SENT\n"); break;
228 case MESSAGESTATE_STAMPED
: printf("STAMPED\n"); break;
229 case MESSAGESTATE_INFECTED
: printf("INFECTED\n"); break;
230 case MESSAGESTATE_DELIVERED
: printf("DELIVERED\n"); break;
231 case MESSAGESTATE_SUBSTITUTED
: printf("SUBSTITUTED\n"); break;
232 case MESSAGESTATE_RECEIVED
: printf("RECEIVED\n"); break;
233 case MESSAGESTATE_READ
: printf("READ\n"); break;
234 case MESSAGESTATE_UNDELIVERABLE
: printf("UNDELIVERABLE\n"); break;
235 case MESSAGESTATE_REMOVED
: printf("REMOVED\n"); break;
236 case MESSAGESTATE_IN_SAFE
: printf("IN_SAFE\n"); break;
237 default: printf("<unknown type %d>\n", *status
);
241 void print_bool(const _Bool
*boolean
) {
242 printf("%s\n", (!boolean
) ? "NULL" : ((*boolean
)? "true" : "false") );
246 void print_longint(const long int *number
) {
247 if (!number
) printf("NULL\n");
248 else printf("%ld\n", *number
);
252 void print_PersonName(const struct isds_PersonName
*personName
) {
253 printf("\tpersonName = ");
254 if (!personName
) printf("NULL\n");
257 printf("\t\tpnFirstName = %s\n", personName
->pnFirstName
);
258 printf("\t\tpnMiddleName = %s\n", personName
->pnMiddleName
);
259 printf("\t\tpnLastName = %s\n", personName
->pnLastName
);
260 printf("\t\tpnLastNameAtBirth = %s\n", personName
->pnLastNameAtBirth
);
266 void print_Address(const struct isds_Address
*address
) {
267 printf("\taddress = ");
268 if (!address
) printf("NULL\n");
272 printf("\t\tadCode = ");
273 print_longint(address
->adCode
);
275 printf("\t\tadCity = %s\n", address
->adCity
);
276 printf("\t\tadDistrict = %s\n", address
->adDistrict
);
277 printf("\t\tadStreet = %s\n", address
->adStreet
);
278 printf("\t\tadNumberInStreet = %s\n", address
->adNumberInStreet
);
279 printf("\t\tadNumberInMunicipality = %s\n",
280 address
->adNumberInMunicipality
);
281 printf("\t\tadZipCode = %s\n", address
->adZipCode
);
282 printf("\t\tadState = %s\n", address
->adState
);
288 void print_date(const struct tm
*date
) {
289 if (!date
) printf("NULL\n");
290 else printf("%s", asctime(date
));
294 void print_DbOwnerInfo(const struct isds_DbOwnerInfo
*info
) {
295 printf("dbOwnerInfo = ");
303 printf("\tdbID = %s\n", info
->dbID
);
305 printf("\tdbType = ");
306 print_DbType((long int *) (info
->dbType
));
307 printf("\tic = %s\n", info
->ic
);
309 print_PersonName(info
->personName
);
311 printf("\tfirmName = %s\n", info
->firmName
);
313 printf("\tbirthInfo = ");
314 if (!info
->birthInfo
) printf("NULL\n");
318 printf("\t\tbiDate = ");
319 print_date(info
->birthInfo
->biDate
);
321 printf("\t\tbiCity = %s\n", info
->birthInfo
->biCity
);
322 printf("\t\tbiCounty = %s\n", info
->birthInfo
->biCounty
);
323 printf("\t\tbiState = %s\n", info
->birthInfo
->biState
);
327 print_Address(info
->address
);
329 printf("\tnationality = %s\n", info
->nationality
);
330 printf("\temail = %s\n", info
->email
);
331 printf("\ttelNumber = %s\n", info
->telNumber
);
332 printf("\tidentifier = %s\n", info
->identifier
);
334 printf("\taifoIsds = ");
335 print_bool(info
->aifoIsds
);
337 printf("\tregistryCode = %s\n", info
->registryCode
);
339 printf("\tdbState = ");
340 if (!info
->dbState
) printf("NULL\n");
341 else print_DbState(*(info
->dbState
));
343 printf("\tdbEffectiveOVM = ");
344 print_bool(info
->dbEffectiveOVM
);
346 printf("\tdbOpenAddressing = ");
347 print_bool(info
->dbOpenAddressing
);
354 void print_DbUserInfo(const struct isds_DbUserInfo
*info
) {
355 printf("dbUserInfo = ");
363 printf("\tuserID = %s\n", info
->userID
);
365 printf("\tuserType = ");
366 print_UserType((long int *) (info
->userType
));
368 printf("\tuserPrivils = ");
369 print_UserPrivils(info
->userPrivils
);
371 print_PersonName(info
->personName
);
372 print_Address(info
->address
);
374 printf("\tbiDate = ");
375 print_date(info
->biDate
);
377 printf("\tic = %s\n", info
->ic
);
378 printf("\tfirmName = %s\n", info
->firmName
);
380 printf("\tcaStreet = %s\n", info
->caStreet
);
381 printf("\tcaCity = %s\n", info
->caCity
);
382 printf("\tcaZipCode = %s\n", info
->caZipCode
);
383 printf("\tcaState = %s\n", info
->caState
);
384 printf("\taifo_ticket = %s\n", info
->aifo_ticket
);
390 void print_timeval(const struct timeval
*time
) {
393 time_t seconds_as_time_t
;
400 /* MinGW32 GCC 4.8+ uses 64-bit time_t but time->tv_sec is defined as
401 * 32-bit long in Microsoft API. Convert value to the type expected by
403 seconds_as_time_t
= time
->tv_sec
;
404 if (!localtime_r(&seconds_as_time_t
, &broken
)) goto error
;
405 if (!strftime(buffer
, sizeof(buffer
)/sizeof(char), "%c", &broken
))
407 printf("%s, %" PRIdMAX
" us\n", buffer
, (intmax_t)time
->tv_usec
);
411 printf("<Error while formating>\n>");
416 void print_event_type(const isds_event_type
*type
) {
422 case EVENT_UKNOWN
: printf("UNKNOWN\n"); break;
423 case EVENT_ENTERED_SYSTEM
: printf("ENTERED_SYSTEM\n"); break;
424 case EVENT_ACCEPTED_BY_RECIPIENT
:
425 printf("ACCEPTED_BY_RECIPIENT\n"); break;
426 case EVENT_ACCEPTED_BY_FICTION
:
427 printf("DELIVERED_BY_FICTION\n"); break;
428 case EVENT_UNDELIVERABLE
:
429 printf("UNDELIVERABLE\n"); break;
430 case EVENT_COMMERCIAL_ACCEPTED
:
431 printf("COMMERCIAL_ACCEPTED\n"); break;
432 case EVENT_DELIVERED
:
433 printf("DELIVERED\n"); break;
434 case EVENT_PRIMARY_LOGIN
:
435 printf("PRIMARY_LOGIN\n"); break;
436 case EVENT_ENTRUSTED_LOGIN
:
437 printf("ENTRUSTED_LOGIN\n"); break;
438 case EVENT_SYSCERT_LOGIN
:
439 printf("SYSCERT_LOGIN\n"); break;
440 default: printf("<unknown type %d>\n", *type
);
445 void print_events(const struct isds_list
*events
) {
446 const struct isds_list
*item
;
447 const struct isds_event
*event
;
456 for (item
= events
; item
; item
= item
->next
) {
457 event
= (struct isds_event
*) item
->data
;
458 printf("\t\t\tevent = ");
459 if (!event
) printf("NULL");
463 printf("\t\t\t\ttype = ");
464 print_event_type(event
->type
);
466 printf("\t\t\t\tdescription = %s\n", event
->description
);
468 printf("\t\t\t\ttime = ");
469 print_timeval(event
->time
);
479 void print_envelope(const struct isds_envelope
*envelope
) {
480 printf("\tenvelope = ");
488 printf("\t\tdmID = %s\n", envelope
->dmID
);
489 printf("\t\tdbIDSender = %s\n", envelope
->dbIDSender
);
490 printf("\t\tdmSender = %s\n", envelope
->dmSender
);
491 printf("\t\tdmSenderAddress = %s\n", envelope
->dmSenderAddress
);
492 printf("\t\tdmSenderType = ");
493 print_DbType(envelope
->dmSenderType
);
494 printf("\t\tdmRecipient = %s\n", envelope
->dmRecipient
);
495 printf("\t\tdmRecipientAddress = %s\n", envelope
->dmRecipientAddress
);
496 printf("\t\tdmAmbiguousRecipient = ");
497 print_bool(envelope
->dmAmbiguousRecipient
);
498 printf("\t\tdmType = %s\n", envelope
->dmType
);
500 printf("\t\tdmSenderOrgUnit = %s\n", envelope
->dmSenderOrgUnit
);
501 printf("\t\tdmSenderOrgUnitNum = ");
502 print_longint(envelope
->dmSenderOrgUnitNum
);
503 printf("\t\tdbIDRecipient = %s\n", envelope
->dbIDRecipient
);
504 printf("\t\tdmRecipientOrgUnit = %s\n", envelope
->dmRecipientOrgUnit
);
505 printf("\t\tdmRecipientOrgUnitNum = ");
506 print_longint(envelope
->dmRecipientOrgUnitNum
);
507 printf("\t\tdmToHands = %s\n", envelope
->dmToHands
);
508 printf("\t\tdmAnnotation = %s\n", envelope
->dmAnnotation
);
509 printf("\t\tdmRecipientRefNumber = %s\n", envelope
->dmRecipientRefNumber
);
510 printf("\t\tdmSenderRefNumber = %s\n", envelope
->dmSenderRefNumber
);
511 printf("\t\tdmRecipientIdent = %s\n", envelope
->dmRecipientIdent
);
512 printf("\t\tdmSenderIdent = %s\n", envelope
->dmSenderIdent
);
514 printf("\t\tdmLegalTitleLaw = ");
515 print_longint(envelope
->dmLegalTitleLaw
);
516 printf("\t\tdmLegalTitleYear = ");
517 print_longint(envelope
->dmLegalTitleYear
);
518 printf("\t\tdmLegalTitleSect = %s\n", envelope
->dmLegalTitleSect
);
519 printf("\t\tdmLegalTitlePar = %s\n", envelope
->dmLegalTitlePar
);
520 printf("\t\tdmLegalTitlePoint = %s\n", envelope
->dmLegalTitlePoint
);
522 printf("\t\tdmPersonalDelivery = ");
523 print_bool(envelope
->dmPersonalDelivery
);
524 printf("\t\tdmAllowSubstDelivery = ");
525 print_bool(envelope
->dmAllowSubstDelivery
);
526 printf("\t\tdmOVM = ");
527 print_bool(envelope
->dmOVM
);
528 printf("\t\tdmPublishOwnID = ");
529 print_bool(envelope
->dmPublishOwnID
);
531 printf("\t\tdmOrdinal = ");
532 if (!envelope
->dmOrdinal
) printf("NULL\n");
533 else printf("%lu\n", *(envelope
->dmOrdinal
));
535 printf("\t\tdmMessageStatus = ");
536 print_dmMessageStatus(envelope
->dmMessageStatus
);
538 printf("\t\tdmAttachmentSize = ");
539 if (!envelope
->dmAttachmentSize
) printf("NULL\n");
540 else printf("%lu kB\n", *(envelope
->dmAttachmentSize
));
542 printf("\t\tdmDeliveryTime = ");
543 print_timeval(envelope
->dmDeliveryTime
);
545 printf("\t\tdmAcceptanceTime = ");
546 print_timeval(envelope
->dmAcceptanceTime
);
548 printf("\t\thash = ");
549 print_hash(envelope
->hash
);
551 printf("\t\ttimestamp = %p\n", envelope
->timestamp
);
552 printf("\t\ttimestamp_length = %zu\n", envelope
->timestamp_length
);
554 printf("\t\tevents = ");
555 print_events(envelope
->events
);
561 void print_document(const struct isds_document
*document
) {
562 printf("\t\tdocument = ");
570 printf("\t\t\tis_xml = %u\n", !!document
->is_xml
);
571 printf("\t\t\txml_node_list = %p\n", document
->xml_node_list
);
573 printf("\t\t\tdata = %p\n", document
->data
);
574 printf("\t\t\tdata_length = %zu\n", document
->data_length
);
575 printf("\t\t\tdmMimeType = %s\n", document
->dmMimeType
);
577 printf("\t\t\tdmFileMetaType = ");
578 switch(document
->dmFileMetaType
) {
579 case FILEMETATYPE_MAIN
: printf("MAIN\n"); break;
580 case FILEMETATYPE_ENCLOSURE
: printf("ENCLOSURE\n"); break;
581 case FILEMETATYPE_SIGNATURE
: printf("SIGNATURE\n"); break;
582 case FILEMETATYPE_META
: printf("META\n"); break;
583 default: printf("<unknown type %d>\n", document
->dmFileMetaType
);
586 printf("\t\t\tdmFileGuid = %s\n", document
->dmFileGuid
);
587 printf("\t\t\tdmUpFileGuid = %s\n", document
->dmUpFileGuid
);
588 printf("\t\t\tdmFileDescr = %s\n", document
->dmFileDescr
);
589 printf("\t\t\tdmFormat = %s\n", document
->dmFormat
);
594 void print_documents(const struct isds_list
*documents
) {
595 const struct isds_list
*item
;
597 printf("\tdocuments = ");
605 for (item
= documents
; item
; item
= item
->next
) {
606 print_document((struct isds_document
*) (item
->data
));
613 void print_message(const struct isds_message
*message
) {
614 printf("message = ");
623 printf("\traw = %p\n", message
->raw
);
624 printf("\traw_length = %zu\n", message
->raw_length
);
625 printf("\traw_type = ");
626 print_raw_type(message
->raw_type
);
627 printf("\txml = %p\n", message
->xml
);
628 print_envelope(message
->envelope
);
629 print_documents(message
->documents
);
634 void print_copies(const struct isds_list
*copies
) {
635 const struct isds_list
*item
;
636 struct isds_message_copy
*copy
;
645 for (item
= copies
; item
; item
= item
->next
) {
646 copy
= (struct isds_message_copy
*) item
->data
;
653 printf("\t\tdbIDRecipient = %s\n", copy
->dbIDRecipient
);
654 printf("\t\tdmRecipientOrgUnit = %s\n", copy
->dmRecipientOrgUnit
);
656 printf("\t\tdmRecipientOrgUnitNum = ");
657 if (copy
->dmRecipientOrgUnitNum
)
658 printf("%ld\n", *copy
->dmRecipientOrgUnitNum
);
661 printf("\t\tdmToHands = %s\n", copy
->dmToHands
);
663 printf("\t\terror = %s\n", isds_strerror(copy
->error
));
664 printf("\t\tdmStatus = %s\n", copy
->dmStatus
);
665 printf("\t\tdmID = %s\n", copy
->dmID
);
672 void print_message_status_change(
673 const struct isds_message_status_change
*changed_status
) {
674 printf("message_status_change = ");
676 if (!changed_status
) {
683 printf("\tdmID = %s\n", changed_status
->dmID
);
685 printf("\tdmMessageStatus = ");
686 print_dmMessageStatus(changed_status
->dmMessageStatus
);
689 print_timeval(changed_status
->time
);
694 void compare_hashes(const struct isds_hash
*hash1
,
695 const struct isds_hash
*hash2
) {
698 printf("Comparing hashes... ");
699 err
= isds_hash_cmp(hash1
, hash2
);
700 if (err
== IE_SUCCESS
)
701 printf("Hashes equal\n");
703 (err
== IE_NOTEQUAL
) printf("Hashes differ\n");
705 printf("isds_hash_cmp() failed: %s\n", isds_strerror(err
));
709 int progressbar(double upload_total
, double upload_current
,
710 double download_total
, double download_current
,
713 printf("Progress: upload %0f/%0f, download %0f/%0f, data=%p\n",
714 upload_current
, upload_total
, download_current
, download_total
,
717 printf("Aborting transfer...\n");
724 int mmap_file(const char *file
, int *fd
, void **buffer
, size_t *length
) {
725 struct stat file_info
;
727 if (!file
|| !fd
|| !buffer
|| !length
) return -1;
730 *fd
= open(file
, O_RDONLY
);
732 fprintf(stderr
, "%s: Could not open file: %s\n", file
, strerror(errno
));
736 if (-1 == fstat(*fd
, &file_info
)) {
737 fprintf(stderr
, "%s: Could not get file size: %s\n", file
,
742 if (file_info
.st_size
< 0) {
743 fprintf(stderr
, "File `%s' has negative size: %" PRIdMAX
"\n", file
,
744 (intmax_t) file_info
.st_size
);
748 *length
= file_info
.st_size
;
751 /* Empty region cannot be mmapped */
754 *buffer
= mmap(NULL
, *length
, PROT_READ
, MAP_PRIVATE
, *fd
, 0);
755 if (*buffer
== MAP_FAILED
) {
756 fprintf(stderr
, "%s: Could not map file to memory: %s\n", file
,
767 int munmap_file(int fd
, void *buffer
, size_t length
) {
769 long int page_size
= sysconf(_SC_PAGE_SIZE
);
770 size_t pages
= (length
% page_size
) ?
771 ((length
/ page_size
) + 1) * page_size
:
775 err
= munmap(buffer
, pages
);
778 "Could not unmap memory at %p and length %zu: %s\n",
779 buffer
, pages
, strerror(errno
));
785 fprintf(stderr
, "Could close file descriptor %d: %s\n", fd
,
793 static int save_data_to_file(const char *file
, const void *data
,
794 const size_t length
) {
796 ssize_t written
, left
= length
;
798 if (!file
) return -1;
799 if (length
> 0 && !data
) return -1;
801 fd
= open(file
, O_WRONLY
|O_TRUNC
|O_CREAT
, 0666);
803 fprintf(stderr
, "%s: Could not open file for writing: %s\n",
804 file
, strerror(errno
));
808 printf("Writing %zu bytes to file `%s'...\n", length
, file
);
810 written
= write(fd
, data
+ length
- left
, left
);
812 fprintf(stderr
, "%s: Could not save file: %s\n",
813 file
, strerror(errno
));
820 if (-1 == close(fd
)) {
821 fprintf(stderr
, "%s: Closing file failed: %s\n",
822 file
, strerror(errno
));
831 int save_data(const char *message
, const void *data
, const size_t length
) {
833 printf("%s\n", message
);
834 return save_data_to_file("output", data
, length
);