• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 ** Copyright (C) 2010-2017 Erik de Castro Lopo <erikd@mega-nerd.com>
3 **
4 ** This program is free software; you can redistribute it and/or modify
5 ** it under the terms of the GNU Lesser General Public License as published by
6 ** the Free Software Foundation; either version 2.1 of the License, or
7 ** (at your option) any later version.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 ** GNU Lesser General Public License for more details.
13 **
14 ** You should have received a copy of the GNU Lesser General Public License
15 ** along with this program; if not, write to the Free Software
16 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 
19 #include	"sfconfig.h"
20 
21 #include	<stdio.h>
22 #include	<fcntl.h>
23 #include	<string.h>
24 #include	<ctype.h>
25 
26 #include	"sndfile.h"
27 #include	"sfendian.h"
28 #include	"common.h"
29 
30 int
id3_skip(SF_PRIVATE * psf)31 id3_skip (SF_PRIVATE * psf)
32 {	unsigned char	buf [10] ;
33 
34 	memset (buf, 0, sizeof (buf)) ;
35 	psf_binheader_readf (psf, "pb", 0, buf, 10) ;
36 
37 	if (buf [0] == 'I' && buf [1] == 'D' && buf [2] == '3')
38 	{	int	offset = buf [6] & 0x7f ;
39 		offset = (offset << 7) | (buf [7] & 0x7f) ;
40 		offset = (offset << 7) | (buf [8] & 0x7f) ;
41 		offset = (offset << 7) | (buf [9] & 0x7f) ;
42 
43 		psf_log_printf (psf, "ID3 length : %d\n--------------------\n", offset) ;
44 
45 		/* Never want to jump backwards in a file. */
46 		if (offset < 0)
47 			return 0 ;
48 
49 		/* Calculate new file offset and position ourselves there. */
50 		offset += 10 ;
51 		if (psf->fileoffset + offset < psf->filelength)
52 		{	psf_binheader_readf (psf, "p", offset) ;
53 			psf->fileoffset += offset ;
54 			return 1 ;
55 			} ;
56 		} ;
57 
58 	return 0 ;
59 } /* id3_skip */
60