/* Creates and returns a new line_reader that reads its input from FD. Returns a new line_reader if successful, otherwise returns NULL and sets errno to an appropriate value. The accepted forms for ENCODING are listed at the top of encoding-guesser.h. */ struct line_reader * line_reader_for_fd (const char *encoding, int fd) { struct line_reader *r; r = calloc (1, sizeof *r); if (r == NULL) return NULL; r->fd = fd; r->buffer = malloc (LINE_READER_BUFFER_SIZE); if (r->buffer == NULL) goto error; r->head = r->buffer; r->length = 0; if (fill_buffer (r) < 0) goto error; r->encoding = xstrdup (encoding_guess_head_encoding ( encoding, r->buffer, r->length)); if (!get_encoding_info (&r->encoding_info, r->encoding)) { errno = EINVAL; goto error; } if (encoding_guess_encoding_is_auto (encoding) && !strcmp (r->encoding, "ASCII")) { r->state = S_AUTO; r->auto_encoding = encoding ? xstrdup (encoding) : NULL; } else r->state = r->encoding_info.unit == 1 ? S_UNIBYTE : S_MULTIBYTE; return r; error: line_reader_free (r); return NULL; }
/* exported, looks at all possible instr_info_t templates */ bool instr_is_encoding_possible(instr_t *instr) { const instr_info_t *info = get_encoding_info(instr); return (info != NULL); }