| 776 | extern int errno; |
| 777 | |
| 778 | void |
| 779 | port_insert_pastebuf(char *buf) |
| 780 | { |
| 781 | /* This should be replaced when there is a Cocoa port. */ |
| 782 | const char *errarg; |
| 783 | size_t len; |
| 784 | FILE *PB = popen("/usr/bin/pbcopy", "w"); |
| 785 | |
| 786 | if (!PB) { |
| 787 | errarg = "Unable to start pbcopy"; |
| 788 | goto error; |
| 789 | } |
| 790 | |
| 791 | len = strlen(buf); |
| 792 | /* Remove the trailing \n, carefully. */ |
| 793 | if (len > 0 && buf[len - 1] == '\n') |
| 794 | len--; |
| 795 | |
| 796 | /* XXX Sorry, I'm too lazy to write a loop for output this short. */ |
| 797 | if (len != fwrite(buf, 1, len, PB)) { |
| 798 | errarg = "Error sending data to pbcopy"; |
| 799 | goto error; |
| 800 | } |
| 801 | |
| 802 | if (pclose(PB) != -1) { |
| 803 | return; |
| 804 | } |
| 805 | errarg = "Error finishing pbcopy"; |
| 806 | |
| 807 | error: |
| 808 | raw_printf("%s: %s (%d)\n", errarg, strerror(errno), errno); |
| 809 | } |
| 810 | #endif /* __APPLE__ */ |
| 811 | |
| 812 | unsigned long |
no test coverage detected