Revision 3e1a8e1e

View differences:

libavformat/avio.h
526 526
uint64_t     avio_rl64(AVIOContext *s);
527 527

  
528 528
/**
529
 * Read a string from pb into buf. The reading will terminate when either
530
 * a NULL character was encountered, maxlen bytes have been read, or nothing
531
 * more can be read from pb. The result is guaranteed to be NULL-terminated, it
532
 * will be truncated if buf is too small.
533
 * Note that the string is not interpreted or validated in any way, it
534
 * might get truncated in the middle of a sequence for multi-byte encodings.
535
 *
536
 * @return number of bytes read (is always <= maxlen).
537
 * If reading ends on EOF or error, the return value will be one more than
538
 * bytes actually read.
539
 */
540
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen);
541

  
542
/**
529 543
 * Read a UTF-16 string from pb and convert it to UTF-8.
530 544
 * The reading will terminate when either a null or invalid character was
531 545
 * encountered or maxlen bytes have been read.
libavformat/aviobuf.c
705 705
    return i;
706 706
}
707 707

  
708
int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen)
709
{
710
    int i;
711

  
712
    // reserve 1 byte for terminating 0
713
    buflen = FFMIN(buflen - 1, maxlen);
714
    for (i = 0; i < buflen; i++)
715
        if (!(buf[i] = avio_r8(s)))
716
            return i + 1;
717
    if (buflen)
718
        buf[i] = 0;
719
    for (; i < maxlen; i++)
720
        if (!avio_r8(s))
721
            return i + 1;
722
    return maxlen;
723
}
724

  
708 725
#define GET_STR16(type, read) \
709 726
    int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\
710 727
{\

Also available in: Unified diff