⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 util.c

📁 realmedia解压源码
💻 C
字号:
/***************************************************************************** * libreal  -  A library for writing and extracting data streams to and from * *             RealMedia files.                                              * * Copyright (C) 2001 Leo Howell                                             * *                                                                           * * This program is free software; you can redistribute it and/or modify      * * it under the terms of the GNU General Public License as published by      * * the Free Software Foundation; either version 2 of the License, or         * * (at your option) and later version.                                       * *                                                                           * * This program is distributed in the hope that it will be useful,           * * but WITHOUT ANY WARRANTY; without even the implied warranty of            * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             * * GNU General Public License for more details.                              * *                                                                           * * You should have received a copy of the GNU General Public License         * * along with this program; if not, write to the Free Software               * * Foundation, Inc., 59 Temple Place, Suite 330, Boston MA  02111-1307  USA  * *                                                                           * * You can contact me by email, leo_howell@users.sourceforge.net             * *****************************************************************************/#include <unistd.h>#include <netinet/in.h> /* for htonl() etc */#include <stdio.h>#include <stdlib.h>#include "util.h"/* * bread32 * Read 32 bits from a stream in network byte order * and store as host byte order */int bread32(int fd, uint32_t *dest){	return (read(fd, dest, 4) < 4)		|| ((*dest = ntohl(*dest)), 0);}/* * bread16 * Read 16 bits from a stream in network byte order * and store as host byte order */int bread16(int fd, uint16_t *dest){	return (read(fd, dest, 2) < 2)		|| ((*dest = ntohs(*dest)), 0);}/* * bread8 * Read 8 bits (one byte) from a stream */int bread8(int fd, uint8_t *dest){	return read(fd, dest, 1) < 1;}/* * breads * Read a string of len bytes from a stream, allocate * space and store. */int breads(int fd, uint8_t **dest, int len){	*dest = malloc(len);	if (*dest == NULL) {		perror("breads: malloc()");		return -1;	}	return read(fd, *dest, len) < len;}/* * bwrite32 * Write 32 bits in host byte order * to a stream in network byte order */int bwrite32(int fd, uint32_t data){	return ((data = htonl(data)),		write(fd, &data, 4) < 4);}/* * bwrite16 * Write 16 bits in host byte order * to a stream in network byte order */int bwrite16(int fd, uint16_t data){	return ((data = htons(data)),		write(fd, &data, 2) < 2);}/* * bwrite8 * Write 8 bits (one byte) to a stream */int bwrite8(int fd, uint8_t data){	return write(fd, &data, 1) < 1;}/* * bwrites * Write a string of bytes to a stream */int bwrites(int fd, const uint8_t *data, int len){	return (data == NULL) || (write(fd, data, len) < len);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -