* xmlNewInputBufferMemory: * @mem: memory buffer * @size: size of buffer * @flags: flags * @enc: the charset encoding if known (deprecated) * * Create an input buffer for memory. * * Returns the new input buffer or NULL. */
| 1962 | * Returns the new input buffer or NULL. |
| 1963 | */ |
| 1964 | xmlParserInputBufferPtr |
| 1965 | xmlNewInputBufferMemory(const void *mem, size_t size, int flags, |
| 1966 | xmlCharEncoding enc) { |
| 1967 | xmlParserInputBufferPtr ret; |
| 1968 | xmlMemIOCtxt *ctxt; |
| 1969 | char *copy = NULL; |
| 1970 | |
| 1971 | if ((flags & XML_INPUT_BUF_STATIC) == 0) { |
| 1972 | if (size + 1 == 0) |
| 1973 | return(NULL); |
| 1974 | copy = xmlMalloc(size + 1); |
| 1975 | if (copy == NULL) |
| 1976 | return(NULL); |
| 1977 | memcpy(copy, mem, size); |
| 1978 | copy[size] = 0; |
| 1979 | |
| 1980 | mem = copy; |
| 1981 | } |
| 1982 | |
| 1983 | ret = xmlAllocParserInputBuffer(enc); |
| 1984 | if (ret == NULL) { |
| 1985 | xmlFree(copy); |
| 1986 | return(NULL); |
| 1987 | } |
| 1988 | |
| 1989 | ctxt = xmlMalloc(sizeof(*ctxt)); |
| 1990 | if (ctxt == NULL) { |
| 1991 | xmlFreeParserInputBuffer(ret); |
| 1992 | xmlFree(copy); |
| 1993 | return(NULL); |
| 1994 | } |
| 1995 | |
| 1996 | ctxt->mem = copy; |
| 1997 | ctxt->cur = mem; |
| 1998 | ctxt->size = size; |
| 1999 | |
| 2000 | ret->context = ctxt; |
| 2001 | ret->readcallback = xmlMemRead; |
| 2002 | ret->closecallback = xmlMemClose; |
| 2003 | |
| 2004 | return(ret); |
| 2005 | } |
| 2006 | |
| 2007 | /** |
| 2008 | * xmlParserInputBufferCreateMem: |
no test coverage detected