ReactOS  0.4.14-dev-323-g6fe6a88
psread.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* psread.c */
4 /* */
5 /* Adobe's code for stream handling (body). */
6 /* */
7 /* Copyright 2007-2013 Adobe Systems Incorporated. */
8 /* */
9 /* This software, and all works of authorship, whether in source or */
10 /* object code form as indicated by the copyright notice(s) included */
11 /* herein (collectively, the "Work") is made available, and may only be */
12 /* used, modified, and distributed under the FreeType Project License, */
13 /* LICENSE.TXT. Additionally, subject to the terms and conditions of the */
14 /* FreeType Project License, each contributor to the Work hereby grants */
15 /* to any individual or legal entity exercising permissions granted by */
16 /* the FreeType Project License and this section (hereafter, "You" or */
17 /* "Your") a perpetual, worldwide, non-exclusive, no-charge, */
18 /* royalty-free, irrevocable (except as stated in this section) patent */
19 /* license to make, have made, use, offer to sell, sell, import, and */
20 /* otherwise transfer the Work, where such license applies only to those */
21 /* patent claims licensable by such contributor that are necessarily */
22 /* infringed by their contribution(s) alone or by combination of their */
23 /* contribution(s) with the Work to which such contribution(s) was */
24 /* submitted. If You institute patent litigation against any entity */
25 /* (including a cross-claim or counterclaim in a lawsuit) alleging that */
26 /* the Work or a contribution incorporated within the Work constitutes */
27 /* direct or contributory patent infringement, then any patent licenses */
28 /* granted to You under this License for that Work shall terminate as of */
29 /* the date such litigation is filed. */
30 /* */
31 /* By using, modifying, or distributing the Work you indicate that you */
32 /* have read and understood the terms and conditions of the */
33 /* FreeType Project License as well as those provided in this section, */
34 /* and you accept them fully. */
35 /* */
36 /***************************************************************************/
37 
38 
39 #include "psft.h"
40 #include FT_INTERNAL_DEBUG_H
41 
42 #include "psglue.h"
43 
44 #include "pserror.h"
45 
46 
47  /* Define CF2_IO_FAIL as 1 to enable random errors and random */
48  /* value errors in I/O. */
49 #define CF2_IO_FAIL 0
50 
51 
52 #if CF2_IO_FAIL
53 
54  /* set the .00 value to a nonzero probability */
55  static int
56  randomError2( void )
57  {
58  /* for region buffer ReadByte (interp) function */
59  return (double)rand() / RAND_MAX < .00;
60  }
61 
62  /* set the .00 value to a nonzero probability */
63  static CF2_Int
64  randomValue()
65  {
66  return (double)rand() / RAND_MAX < .00 ? rand() : 0;
67  }
68 
69 #endif /* CF2_IO_FAIL */
70 
71 
72  /* Region Buffer */
73  /* */
74  /* Can be constructed from a copied buffer managed by */
75  /* `FCM_getDatablock'. */
76  /* Reads bytes with check for end of buffer. */
77 
78  /* reading past the end of the buffer sets error and returns zero */
81  {
82  if ( buf->ptr < buf->end )
83  {
84 #if CF2_IO_FAIL
85  if ( randomError2() )
86  {
87  CF2_SET_ERROR( buf->error, Invalid_Stream_Operation );
88  return 0;
89  }
90 
91  return *(buf->ptr)++ + randomValue();
92 #else
93  return *(buf->ptr)++;
94 #endif
95  }
96  else
97  {
98  CF2_SET_ERROR( buf->error, Invalid_Stream_Operation );
99  return 0;
100  }
101  }
102 
103 
104  /* note: end condition can occur without error */
107  {
108  return (FT_Bool)( buf->ptr >= buf->end );
109  }
110 
111 
112 /* END */
FT_BEGIN_HEADER struct CF2_BufferRec_ * CF2_Buffer
cf2_buf_readByte(CF2_Buffer buf)
Definition: psread.c:80
cf2_buf_isEnd(CF2_Buffer buf)
Definition: psread.c:106
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:388
#define RAND_MAX
Definition: stdlib.h:99
#define CF2_Int
Definition: pstypes.h:65
#define CF2_SET_ERROR(error, e)
Definition: pserror.h:109