File: Get_UTF32i.c

package info (click to toggle)
uniutils 2.28-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,032 kB
  • sloc: ansic: 49,905; sh: 1,168; awk: 55; makefile: 18
file content (39 lines) | stat: -rw-r--r-- 954 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* Time-stamp: <2006-07-12 23:12:12 poser>
 *
 * This function reads from a file descriptor presumed to contain text encoded
 * in native order UTF-32 and returns the next UTF-32 character.
 * No conversion is necessary in this case, so the function is trivial.
 * It is provided for compatibility with functions that actually
 * perform a conversion.
 * 
 * Author: Bill Poser (wjposer@unagi.cis.upenn.edu)
 *
 */

#include <unistd.h>
#include <stdlib.h>
#include "utf8error.h"

#define FALSE 0
#define TRUE 1


typedef unsigned long	UTF32;	/* At least 32 bits */

#define UNI_MAX_UTF32 (UTF32)0x7FFFFFFF


UTF32 Get_UTF32 (int fd, int *bytes,unsigned char **rb)
{
  int BytesRead;
  UTF32 ch;

  BytesRead = read(fd,(void *) &ch,sizeof(UTF32));
  if (BytesRead == 0) return (UTF8_ENDOFFILE);
  if (BytesRead < 0) return (UTF8_IOERROR); 
  *bytes = 4;

  *rb=(unsigned char *)&ch;
  if(ch <= UNI_MAX_UTF32) return(ch);
  else return(UTF8_BADOUTCODE);
}