2 * This file is part of the libserialport project.
4 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
5 * Copyright (C) 2010-2012 Uwe Hermann <uwe@hermann-uwe.de>
6 * Copyright (C) 2013 Martin Ling <martin-libserialport@earth.li>
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as
10 * published by the Free Software Foundation, either version 3 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include <sys/types.h>
35 #include <sys/ioctl.h>
38 #include <IOKit/IOKitLib.h>
39 #include <IOKit/serial/IOSerialKeys.h>
40 #include <sys/syslimits.h>
44 #include "linux/serial.h"
47 #include "libserialport.h"
58 /* Standard baud rates. */
60 #define BAUD_TYPE DWORD
61 #define BAUD(n) {CBR_##n, n}
63 #define BAUD_TYPE speed_t
64 #define BAUD(n) {B##n, n}
72 const struct std_baudrate std_baudrates[] = {
75 * The baudrates 50/75/134/150/200/1800/230400/460800 do not seem to
76 * have documented CBR_* macros.
78 BAUD(110), BAUD(300), BAUD(600), BAUD(1200), BAUD(2400), BAUD(4800),
79 BAUD(9600), BAUD(14400), BAUD(19200), BAUD(38400), BAUD(57600),
80 BAUD(115200), BAUD(128000), BAUD(256000)
82 BAUD(50), BAUD(75), BAUD(110), BAUD(134), BAUD(150), BAUD(200), BAUD(300),
83 BAUD(600), BAUD(1200), BAUD(1800), BAUD(2400), BAUD(4800), BAUD(9600),
84 BAUD(19200), BAUD(38400), BAUD(57600), BAUD(115200), BAUD(230400),
85 #if !defined(__APPLE__) && !defined(__OpenBSD__)
91 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
92 #define NUM_STD_BAUDRATES ARRAY_SIZE(std_baudrates)
94 /* Helper functions. */
95 static enum sp_return validate_port(struct sp_port *port);
96 static struct sp_port **list_append(struct sp_port **list, const char *portname);
97 static enum sp_return get_config(struct sp_port *port, struct port_data *data,
98 struct sp_port_config *config);
99 static enum sp_return set_config(struct sp_port *port, struct port_data *data,
100 const struct sp_port_config *config);
102 enum sp_return sp_get_port_by_name(const char *portname, struct sp_port **port_ptr)
104 struct sp_port *port;
115 if (!(port = malloc(sizeof(struct sp_port))))
118 len = strlen(portname) + 1;
120 if (!(port->name = malloc(len)))
126 memcpy(port->name, portname, len);
129 port->hdl = INVALID_HANDLE_VALUE;
139 enum sp_return sp_copy_port(const struct sp_port *port, struct sp_port **copy_ptr)
146 if (!port || !port->name)
149 return sp_get_port_by_name(port->name, copy_ptr);
152 void sp_free_port(struct sp_port *port)
163 static struct sp_port **list_append(struct sp_port **list, const char *portname)
168 for (count = 0; list[count]; count++);
169 if (!(tmp = realloc(list, sizeof(struct sp_port *) * (count + 2))))
172 if (sp_get_port_by_name(portname, &list[count]) != SP_OK)
174 list[count + 1] = NULL;
178 sp_free_port_list(list);
182 enum sp_return sp_list_ports(struct sp_port ***list_ptr)
184 struct sp_port **list;
187 if (!(list = malloc(sizeof(struct sp_port **))))
195 DWORD max_value_len, max_data_size, max_data_len;
196 DWORD value_len, data_size, data_len;
197 DWORD type, index = 0;
201 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("HARDWARE\\DEVICEMAP\\SERIALCOMM"),
202 0, KEY_QUERY_VALUE, &key) != ERROR_SUCCESS)
207 if (RegQueryInfoKey(key, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
208 &max_value_len, &max_data_size, NULL, NULL) != ERROR_SUCCESS)
213 max_data_len = max_data_size / sizeof(TCHAR);
214 if (!(value = malloc((max_value_len + 1) * sizeof(TCHAR))))
219 if (!(data = malloc((max_data_len + 1) * sizeof(TCHAR))))
225 value_len = max_value_len + 1,
226 data_size = max_data_size,
227 RegEnumValue(key, index, value, &value_len,
228 NULL, &type, (LPBYTE)data, &data_size) == ERROR_SUCCESS)
230 data_len = data_size / sizeof(TCHAR);
231 data[data_len] = '\0';
233 name_len = WideCharToMultiByte(CP_ACP, 0, data, -1, NULL, 0, NULL, NULL)
235 name_len = data_len + 1;
237 if (!(name = malloc(name_len)))
243 WideCharToMultiByte(CP_ACP, 0, data, -1, name, name_len, NULL, NULL);
247 if (type == REG_SZ && !(list = list_append(list, name)))
264 CFMutableDictionaryRef classes;
271 if (IOMasterPort(MACH_PORT_NULL, &master) != KERN_SUCCESS)
277 if (!(classes = IOServiceMatching(kIOSerialBSDServiceValue)))
283 CFDictionarySetValue(classes,
284 CFSTR(kIOSerialBSDTypeKey), CFSTR(kIOSerialBSDAllTypes));
286 if (IOServiceGetMatchingServices(master, classes, &iter) != KERN_SUCCESS)
292 if (!(path = malloc(PATH_MAX)))
298 while ((port = IOIteratorNext(iter))) {
299 cf_path = IORegistryEntryCreateCFProperty(port,
300 CFSTR(kIOCalloutDeviceKey), kCFAllocatorDefault, 0);
302 result = CFStringGetCString(cf_path,
303 path, PATH_MAX, kCFStringEncodingASCII);
305 if (result && !(list = list_append(list, path)))
308 IOObjectRelease(port);
312 IOObjectRelease(port);
317 IOObjectRelease(iter);
322 struct udev_enumerate *ud_enumerate;
323 struct udev_list_entry *ud_list;
324 struct udev_list_entry *ud_entry;
326 struct udev_device *ud_dev, *ud_parent;
329 int fd, ioctl_result;
330 struct serial_struct serial_info;
333 ud_enumerate = udev_enumerate_new(ud);
334 udev_enumerate_add_match_subsystem(ud_enumerate, "tty");
335 udev_enumerate_scan_devices(ud_enumerate);
336 ud_list = udev_enumerate_get_list_entry(ud_enumerate);
337 udev_list_entry_foreach(ud_entry, ud_list)
339 path = udev_list_entry_get_name(ud_entry);
340 ud_dev = udev_device_new_from_syspath(ud, path);
341 /* If there is no parent device, this is a virtual tty. */
342 ud_parent = udev_device_get_parent(ud_dev);
343 if (ud_parent == NULL)
345 udev_device_unref(ud_dev);
348 name = udev_device_get_devnode(ud_dev);
349 /* The serial8250 driver has a hardcoded number of ports.
350 * The only way to tell which actually exist on a given system
351 * is to try to open them and make an ioctl call. */
352 driver = udev_device_get_driver(ud_parent);
353 if (driver && !strcmp(driver, "serial8250"))
355 if ((fd = open(name, O_RDWR | O_NONBLOCK | O_NOCTTY)) < 0)
357 ioctl_result = ioctl(fd, TIOCGSERIAL, &serial_info);
359 if (ioctl_result != 0)
361 if (serial_info.type == PORT_UNKNOWN)
364 list = list_append(list, name);
366 udev_device_unref(ud_dev);
374 udev_enumerate_unref(ud_enumerate);
385 sp_free_port_list(list);
393 void sp_free_port_list(struct sp_port **list)
397 for (i = 0; list[i]; i++)
398 sp_free_port(list[i]);
402 static enum sp_return validate_port(struct sp_port *port)
407 if (port->hdl == INVALID_HANDLE_VALUE)
416 #define CHECK_PORT() do { if (!validate_port(port)) return SP_ERR_ARG; } while (0)
418 enum sp_return sp_open(struct sp_port *port, enum sp_mode flags)
424 DWORD desired_access = 0, flags_and_attributes = 0;
425 char *escaped_port_name;
427 /* Prefix port name with '\\.\' to work with ports above COM9. */
428 if (!(escaped_port_name = malloc(strlen(port->name + 5))))
430 sprintf(escaped_port_name, "\\\\.\\%s", port->name);
432 /* Map 'flags' to the OS-specific settings. */
433 desired_access |= GENERIC_READ;
434 flags_and_attributes = FILE_ATTRIBUTE_NORMAL;
435 if (flags & SP_MODE_RDWR)
436 desired_access |= GENERIC_WRITE;
437 if (flags & SP_MODE_NONBLOCK)
438 flags_and_attributes |= FILE_FLAG_OVERLAPPED;
440 port->hdl = CreateFile(escaped_port_name, desired_access, 0, 0,
441 OPEN_EXISTING, flags_and_attributes, 0);
443 free(escaped_port_name);
445 if (port->hdl == INVALID_HANDLE_VALUE)
449 struct port_data data;
450 struct sp_port_config config;
453 /* Map 'flags' to the OS-specific settings. */
454 if (flags & SP_MODE_RDWR)
455 flags_local |= O_RDWR;
456 if (flags & SP_MODE_RDONLY)
457 flags_local |= O_RDONLY;
458 if (flags & SP_MODE_NONBLOCK)
459 flags_local |= O_NONBLOCK;
461 if ((port->fd = open(port->name, flags_local)) < 0)
464 ret = get_config(port, &data, &config);
472 /* Turn off all serial port cooking. */
473 data.term.c_iflag &= ~(ISTRIP | INLCR | ICRNL);
474 data.term.c_oflag &= ~(ONLCR | OCRNL | ONOCR);
475 #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__)
476 data.term.c_oflag &= ~OFILL;
478 /* Disable canonical mode, and don't echo input characters. */
479 data.term.c_lflag &= ~(ICANON | ECHO);
481 /* Ignore modem status lines; enable receiver */
482 data.term.c_cflag |= (CLOCAL | CREAD);
484 ret = set_config(port, &data, &config);
496 enum sp_return sp_close(struct sp_port *port)
501 /* Returns non-zero upon success, 0 upon failure. */
502 if (CloseHandle(port->hdl) == 0)
504 port->hdl = INVALID_HANDLE_VALUE;
506 /* Returns 0 upon success, -1 upon failure. */
507 if (close(port->fd) == -1)
515 enum sp_return sp_flush(struct sp_port *port)
520 /* Returns non-zero upon success, 0 upon failure. */
521 if (PurgeComm(port->hdl, PURGE_RXCLEAR | PURGE_TXCLEAR) == 0)
524 /* Returns 0 upon success, -1 upon failure. */
525 if (tcflush(port->fd, TCIOFLUSH) < 0)
531 enum sp_return sp_write(struct sp_port *port, const void *buf, size_t count)
541 /* Returns non-zero upon success, 0 upon failure. */
542 if (WriteFile(port->hdl, buf, count, &written, NULL) == 0)
546 /* Returns the number of bytes written, or -1 upon failure. */
547 ssize_t written = write(port->fd, buf, count);
556 enum sp_return sp_read(struct sp_port *port, void *buf, size_t count)
564 DWORD bytes_read = 0;
566 /* Returns non-zero upon success, 0 upon failure. */
567 if (ReadFile(port->hdl, buf, count, &bytes_read, NULL) == 0)
573 /* Returns the number of bytes read, or -1 upon failure. */
574 if ((bytes_read = read(port->fd, buf, count)) < 0)
580 static enum sp_return get_config(struct sp_port *port, struct port_data *data,
581 struct sp_port_config *config)
586 if (!GetCommState(port->hdl, &data->dcb))
589 for (i = 0; i < NUM_STD_BAUDRATES; i++) {
590 if (data->dcb.BaudRate == std_baudrates[i].index) {
591 config->baudrate = std_baudrates[i].value;
596 if (i == NUM_STD_BAUDRATES)
597 /* BaudRate field can be either an index or a custom baud rate. */
598 config->baudrate = data->dcb.BaudRate;
600 config->bits = data->dcb.ByteSize;
602 if (data->dcb.fParity)
603 switch (data->dcb.Parity) {
605 config->parity = SP_PARITY_NONE;
608 config->parity = SP_PARITY_EVEN;
611 config->parity = SP_PARITY_ODD;
617 config->parity = SP_PARITY_NONE;
619 switch (data->dcb.StopBits) {
621 config->stopbits = 1;
624 config->stopbits = 2;
627 config->stopbits = -1;
630 switch (data->dcb.fRtsControl) {
631 case RTS_CONTROL_DISABLE:
632 config->rts = SP_RTS_OFF;
634 case RTS_CONTROL_ENABLE:
635 config->rts = SP_RTS_ON;
637 case RTS_CONTROL_HANDSHAKE:
638 config->rts = SP_RTS_FLOW_CONTROL;
644 config->cts = data->dcb.fOutxCtsFlow ? SP_CTS_FLOW_CONTROL : SP_CTS_IGNORE;
646 switch (data->dcb.fDtrControl) {
647 case DTR_CONTROL_DISABLE:
648 config->dtr = SP_DTR_OFF;
650 case DTR_CONTROL_ENABLE:
651 config->dtr = SP_DTR_ON;
653 case DTR_CONTROL_HANDSHAKE:
654 config->dtr = SP_DTR_FLOW_CONTROL;
660 config->dsr = data->dcb.fOutxDsrFlow ? SP_DSR_FLOW_CONTROL : SP_DSR_IGNORE;
662 if (data->dcb.fInX) {
664 config->xon_xoff = SP_XONXOFF_INOUT;
666 config->xon_xoff = SP_XONXOFF_IN;
669 config->xon_xoff = SP_XONXOFF_OUT;
671 config->xon_xoff = SP_XONXOFF_DISABLED;
676 if (tcgetattr(port->fd, &data->term) < 0)
679 if (ioctl(port->fd, TIOCMGET, &data->controlbits) < 0)
681 for (i = 0; i < NUM_STD_BAUDRATES; i++) {
682 if (cfgetispeed(&data->term) == std_baudrates[i].index) {
683 config->baudrate = std_baudrates[i].value;
688 if (i == NUM_STD_BAUDRATES)
689 config->baudrate = -1;
691 switch (data->term.c_cflag & CSIZE) {
708 if (!(data->term.c_cflag & PARENB) && (data->term.c_iflag & IGNPAR))
709 config->parity = SP_PARITY_NONE;
710 else if (!(data->term.c_cflag & PARENB) || (data->term.c_iflag & IGNPAR))
713 config->parity = (data->term.c_cflag & PARODD) ? SP_PARITY_ODD : SP_PARITY_EVEN;
715 config->stopbits = (data->term.c_cflag & CSTOPB) ? 2 : 1;
717 if (data->term.c_cflag & CRTSCTS) {
718 config->rts = SP_RTS_FLOW_CONTROL;
719 config->cts = SP_CTS_FLOW_CONTROL;
721 config->rts = (data->controlbits & TIOCM_RTS) ? SP_RTS_ON : SP_RTS_OFF;
722 config->cts = SP_CTS_IGNORE;
725 config->dtr = (data->controlbits & TIOCM_DTR) ? SP_DTR_ON : SP_DTR_OFF;
726 config->dsr = SP_DSR_IGNORE;
732 static enum sp_return set_config(struct sp_port *port, struct port_data *data,
733 const struct sp_port_config *config)
738 if (config->baudrate >= 0)
740 for (i = 0; i < NUM_STD_BAUDRATES; i++) {
741 if (config->baudrate == std_baudrates[i].value) {
742 data->dcb.BaudRate = std_baudrates[i].index;
747 if (i == NUM_STD_BAUDRATES)
748 data->dcb.BaudRate = config->baudrate;
751 if (config->bits >= 0)
752 data->dcb.ByteSize = config->bits;
754 if (config->parity >= 0) {
755 switch (config->parity) {
756 /* Note: There's also SPACEPARITY, MARKPARITY (unneeded so far). */
758 data->dcb.Parity = NOPARITY;
761 data->dcb.Parity = EVENPARITY;
764 data->dcb.Parity = ODDPARITY;
771 if (config->stopbits >= 0) {
772 switch (config->stopbits) {
773 /* Note: There's also ONE5STOPBITS == 1.5 (unneeded so far). */
775 data->dcb.StopBits = ONESTOPBIT;
778 data->dcb.StopBits = TWOSTOPBITS;
785 if (config->rts >= 0) {
786 switch (config->rts) {
788 data->dcb.fRtsControl = RTS_CONTROL_DISABLE;
791 data->dcb.fRtsControl = RTS_CONTROL_ENABLE;
793 case SP_RTS_FLOW_CONTROL:
794 data->dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
801 if (config->cts >= 0) {
802 switch (config->cts) {
804 data->dcb.fOutxCtsFlow = FALSE;
806 case SP_CTS_FLOW_CONTROL:
807 data->dcb.fOutxCtsFlow = TRUE;
814 if (config->dtr >= 0) {
815 switch (config->dtr) {
817 data->dcb.fDtrControl = DTR_CONTROL_DISABLE;
820 data->dcb.fDtrControl = DTR_CONTROL_ENABLE;
822 case SP_DTR_FLOW_CONTROL:
823 data->dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
830 if (config->dsr >= 0) {
831 switch (config->dsr) {
833 data->dcb.fOutxDsrFlow = FALSE;
835 case SP_DSR_FLOW_CONTROL:
836 data->dcb.fOutxDsrFlow = TRUE;
843 if (config->xon_xoff >= 0) {
844 switch (config->xon_xoff) {
845 case SP_XONXOFF_DISABLED:
846 data->dcb.fInX = FALSE;
847 data->dcb.fOutX = FALSE;
850 data->dcb.fInX = TRUE;
851 data->dcb.fOutX = FALSE;
854 data->dcb.fInX = FALSE;
855 data->dcb.fOutX = TRUE;
857 case SP_XONXOFF_INOUT:
858 data->dcb.fInX = TRUE;
859 data->dcb.fOutX = TRUE;
866 if (!SetCommState(port->hdl, &data->dcb))
871 if (config->baudrate >= 0)
873 for (i = 0; i < NUM_STD_BAUDRATES; i++) {
874 if (config->baudrate == std_baudrates[i].value) {
875 if (cfsetospeed(&data->term, std_baudrates[i].index) < 0)
878 if (cfsetispeed(&data->term, std_baudrates[i].index) < 0)
884 if (i == NUM_STD_BAUDRATES)
888 if (config->bits >= 0) {
889 data->term.c_cflag &= ~CSIZE;
890 switch (config->bits) {
892 data->term.c_cflag |= CS8;
895 data->term.c_cflag |= CS7;
898 data->term.c_cflag |= CS6;
905 if (config->parity >= 0) {
906 data->term.c_iflag &= ~IGNPAR;
907 data->term.c_cflag &= ~(PARENB | PARODD);
908 switch (config->parity) {
910 data->term.c_iflag |= IGNPAR;
913 data->term.c_cflag |= PARENB;
916 data->term.c_cflag |= PARENB | PARODD;
923 if (config->stopbits >= 0) {
924 data->term.c_cflag &= ~CSTOPB;
925 switch (config->stopbits) {
927 data->term.c_cflag &= ~CSTOPB;
930 data->term.c_cflag |= CSTOPB;
937 if (config->rts >= 0 || config->cts >= 0)
939 /* Asymmetric use of RTS/CTS not supported yet. */
941 if (data->term.c_iflag & CRTSCTS) {
942 /* Flow control can only be disabled for both RTS & CTS together. */
943 if (config->rts >= 0 && config->rts != SP_RTS_FLOW_CONTROL) {
944 if (config->cts != SP_CTS_IGNORE)
947 if (config->cts >= 0 && config->cts != SP_CTS_FLOW_CONTROL) {
948 if (config->rts <= 0 || config->rts == SP_RTS_FLOW_CONTROL)
952 /* Flow control can only be enabled for both RTS & CTS together. */
953 if (((config->rts == SP_RTS_FLOW_CONTROL) && (config->cts != SP_CTS_FLOW_CONTROL)) ||
954 ((config->cts == SP_CTS_FLOW_CONTROL) && (config->rts != SP_RTS_FLOW_CONTROL)))
958 if (config->rts >= 0) {
959 if (config->rts == SP_RTS_FLOW_CONTROL) {
960 data->term.c_iflag |= CRTSCTS;
962 int controlbits = TIOCM_RTS;
963 if (ioctl(port->fd, config->rts == SP_RTS_ON ? TIOCMBIS : TIOCMBIC,
970 if (config->dtr >= 0 || config->dsr >= 0)
972 /* DTR/DSR flow control not supported yet. */
973 if (config->dtr == SP_DTR_FLOW_CONTROL || config->dsr == SP_DSR_FLOW_CONTROL)
976 if (config->dtr >= 0) {
977 int controlbits = TIOCM_DTR;
978 if (ioctl(port->fd, config->dtr == SP_DTR_ON ? TIOCMBIS : TIOCMBIC,
984 if (config->xon_xoff >= 0) {
985 data->term.c_iflag &= ~(IXON | IXOFF | IXANY);
986 switch (config->xon_xoff) {
987 case SP_XONXOFF_DISABLED:
990 data->term.c_iflag |= IXOFF;
993 data->term.c_iflag |= IXON | IXANY;
995 case SP_XONXOFF_INOUT:
996 data->term.c_iflag |= IXON | IXOFF | IXANY;
1003 if (tcsetattr(port->fd, TCSADRAIN, &data->term) < 0)
1010 #define TRY(x) do { int ret = x; if (ret != SP_OK) return ret; } while (0)
1012 enum sp_return sp_set_config(struct sp_port *port, const struct sp_port_config *config)
1014 struct port_data data;
1015 struct sp_port_config prev_config;
1022 TRY(get_config(port, &data, &prev_config));
1023 TRY(set_config(port, &data, config));
1028 #define CREATE_SETTER(x, type) int sp_set_##x(struct sp_port *port, type x) { \
1029 struct port_data data; \
1030 struct sp_port_config config; \
1032 TRY(get_config(port, &data, &config)); \
1034 TRY(set_config(port, &data, &config)); \
1038 CREATE_SETTER(baudrate, int)
1039 CREATE_SETTER(bits, int)
1040 CREATE_SETTER(parity, enum sp_parity)
1041 CREATE_SETTER(stopbits, int)
1042 CREATE_SETTER(rts, enum sp_rts)
1043 CREATE_SETTER(cts, enum sp_cts)
1044 CREATE_SETTER(dtr, enum sp_dtr)
1045 CREATE_SETTER(dsr, enum sp_dsr)
1046 CREATE_SETTER(xon_xoff, enum sp_xonxoff)
1048 enum sp_return sp_set_flowcontrol(struct sp_port *port, enum sp_flowcontrol flowcontrol)
1050 struct port_data data;
1051 struct sp_port_config config;
1055 TRY(get_config(port, &data, &config));
1057 if (flowcontrol == SP_FLOWCONTROL_XONXOFF)
1058 config.xon_xoff = SP_XONXOFF_INOUT;
1060 config.xon_xoff = SP_XONXOFF_DISABLED;
1062 if (flowcontrol == SP_FLOWCONTROL_RTSCTS) {
1063 config.rts = SP_RTS_FLOW_CONTROL;
1064 config.cts = SP_CTS_FLOW_CONTROL;
1066 if (config.rts == SP_RTS_FLOW_CONTROL)
1067 config.rts = SP_RTS_ON;
1068 config.cts = SP_CTS_IGNORE;
1071 if (flowcontrol == SP_FLOWCONTROL_DTRDSR) {
1072 config.dtr = SP_DTR_FLOW_CONTROL;
1073 config.dsr = SP_DSR_FLOW_CONTROL;
1075 if (config.dtr == SP_DTR_FLOW_CONTROL)
1076 config.dtr = SP_DTR_ON;
1077 config.dsr = SP_DSR_IGNORE;
1080 TRY(set_config(port, &data, &config));
1085 int sp_last_error_code(void)
1088 return GetLastError();
1094 char *sp_last_error_message(void)
1098 DWORD error = GetLastError();
1101 FORMAT_MESSAGE_ALLOCATE_BUFFER |
1102 FORMAT_MESSAGE_FROM_SYSTEM |
1103 FORMAT_MESSAGE_IGNORE_INSERTS,
1106 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1112 return strerror(errno);
1116 void sp_free_error_message(char *message)