pthread的类型定义,好像都在这里。
/* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#ifndef _BITS_PTHREADTYPES_H BITS PTHREAD TYPES
#define _BITS_PTHREADTYPES_H 1
#include <bits/wordsize.h>
#if __WORDSIZE == 64 WORD如果64位,说明一个字节32位。 这个是个什么情况呢?
# define __SIZEOF_PTHREAD_ATTR_T 56
# define __SIZEOF_PTHREAD_MUTEX_T 40
# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
# define __SIZEOF_PTHREAD_COND_T 48
# define __SIZEOF_PTHREAD_CONDATTR_T 4
# define __SIZEOF_PTHREAD_RWLOCK_T 56
# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
# define __SIZEOF_PTHREAD_BARRIER_T 32
# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
#else
# define __SIZEOF_PTHREAD_ATTR_T 36
# define __SIZEOF_PTHREAD_MUTEX_T 24
# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
# define __SIZEOF_PTHREAD_COND_T 48
# define __SIZEOF_PTHREAD_CONDATTR_T 4
# define __SIZEOF_PTHREAD_RWLOCK_T 32
# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
# define __SIZEOF_PTHREAD_BARRIER_T 20
# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
#endif
/* Thread identifiers. The structure of the attribute type is not
exposed on purpose. */ 线程标识符。这个属性类型的结构故意没暴露,啥意思呢?
typedef unsigned long int pthread_t; 是无符号长整型。
typedef union
{
char __size[__SIZEOF_PTHREAD_ATTR_T];
long int __align;
} pthread_attr_t; 是对动态分配的属性结构的一个引用。
#if __WORDSIZE == 64 如果字是64位
typedef struct __pthread_internal_list 内部列表,就是双向链表
{
struct __pthread_internal_list *__prev; 链表的前指针
struct __pthread_internal_list *__next; 链表的后指针
} __pthread_list_t;
#else 否则是单向链表。
typedef struct __pthread_internal_slist
{
struct __pthread_internal_slist *__next;
} __pthread_slist_t;
#endif
/* Data structures for mutex handling. The structure of the attribute
type is not exposed on purpose. */ 互斥处理的数据结构。这个属性类型的结构也是故意未暴露。
typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
#if __WORDSIZE == 64
unsigned int __nusers;
#endif
/* KIND must stay at this position in the structure to maintain
binary compatibility. */
int __kind;
#if __WORDSIZE == 64
int __spins;
__pthread_list_t __list;
# define __PTHREAD_MUTEX_HAVE_PREV 1
#else
unsigned int __nusers;
__extension__ union
{
int __spins;
__pthread_slist_t __list;
};
#endif
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
typedef union
{
char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
int __align;
} pthread_mutexattr_t; 互斥属性类型
/* Data structure for conditional variable handling. The structure of
the attribute type is not exposed on purpose. */ 条件变量处理
typedef union
{
struct
{
int __lock;
unsigned int __futex;
__extension__ unsigned long long int __total_seq;
__extension__ unsigned long long int __wakeup_seq;
__extension__ unsigned long long int __woken_seq;
void *__mutex;
unsigned int __nwaiters;
unsigned int __broadcast_seq;
} __data;
char __size[__SIZEOF_PTHREAD_COND_T];
__extension__ long long int __align;
} pthread_cond_t; 条件类型
typedef union
{
char __size[__SIZEOF_PTHREAD_CONDATTR_T];
int __align;
} pthread_condattr_t; 条件属性类型
/* Keys for thread-specific data */ 线程关键数据的keys
typedef unsigned int pthread_key_t; key类型是无符号整型。
/* Once-only execution */ 仅仅执行一次的类型,是int类型。
typedef int pthread_once_t;
#if defined __USE_UNIX98 || defined __USE_XOPEN2K
/* Data structure for read-write lock variable handling. The
structure of the attribute type is not exposed on purpose. */ 读写锁变量处理。
typedef union
{
# if __WORDSIZE == 64
struct
{
int __lock;
unsigned int __nr_readers;
unsigned int __readers_wakeup;
unsigned int __writer_wakeup;
unsigned int __nr_readers_queued;
unsigned int __nr_writers_queued;
int __writer;
int __shared;
unsigned long int __pad1;
unsigned long int __pad2;
/* FLAGS must stay at this position in the structure to maintain
binary compatibility. */
unsigned int __flags;
} __data;
# else word非64位,定义下面这个结构体
struct
{
int __lock;
unsigned int __nr_readers;
unsigned int __readers_wakeup;
unsigned int __writer_wakeup;
unsigned int __nr_readers_queued;
unsigned int __nr_writers_queued;
/* FLAGS must stay at this position in the structure to maintain
binary compatibility. */
unsigned char __flags;
unsigned char __shared;
unsigned char __pad1;
unsigned char __pad2;
int __writer;
} __data;
# endif
char __size[__SIZEOF_PTHREAD_RWLOCK_T];
long int __align;
} pthread_rwlock_t;
typedef union
{
char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
long int __align;
} pthread_rwlockattr_t;
#endif
#ifdef __USE_XOPEN2K
/* POSIX spinlock data type. */ spinlock数据类型
typedef volatile int pthread_spinlock_t; volatile int
/* POSIX barriers data type. The structure of the type is
deliberately not exposed. */
typedef union
{
char __size[__SIZEOF_PTHREAD_BARRIER_T];
long int __align;
} pthread_barrier_t;
typedef union
{
char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
int __align;
} pthread_barrierattr_t;
#endif
#if __WORDSIZE == 32
/* Extra attributes for the cleanup functions. */ 清理函数的额外属性
# define __cleanup_fct_attribute __attribute__ ((__regparm__ (1)))
#endif
#endif /* bits/pthreadtypes.h */
===============================================
/usr/include/bits/pthreadtypes.h
/* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
#ifndef _BITS_PTHREADTYPES_H
#define _BITS_PTHREADTYPES_H 1
#include <bits/wordsize.h>
#if __WORDSIZE == 64
# define __SIZEOF_PTHREAD_ATTR_T 56
# define __SIZEOF_PTHREAD_MUTEX_T 40
# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
# define __SIZEOF_PTHREAD_COND_T 48
# define __SIZEOF_PTHREAD_CONDATTR_T 4
# define __SIZEOF_PTHREAD_RWLOCK_T 56
# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
# define __SIZEOF_PTHREAD_BARRIER_T 32
# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
#else
# define __SIZEOF_PTHREAD_ATTR_T 36
# define __SIZEOF_PTHREAD_MUTEX_T 24
# define __SIZEOF_PTHREAD_MUTEXATTR_T 4
# define __SIZEOF_PTHREAD_COND_T 48
# define __SIZEOF_PTHREAD_CONDATTR_T 4
# define __SIZEOF_PTHREAD_RWLOCK_T 32
# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
# define __SIZEOF_PTHREAD_BARRIER_T 20
# define __SIZEOF_PTHREAD_BARRIERATTR_T 4
#endif
/* Thread identifiers. The structure of the attribute type is not
exposed on purpose. */
typedef unsigned long int pthread_t;
typedef union
{
char __size[__SIZEOF_PTHREAD_ATTR_T];
long int __align;
} pthread_attr_t;
#if __WORDSIZE == 64
typedef struct __pthread_internal_list
{
struct __pthread_internal_list *__prev;
struct __pthread_internal_list *__next;
} __pthread_list_t;
#else
typedef struct __pthread_internal_slist
{
struct __pthread_internal_slist *__next;
} __pthread_slist_t;
#endif
/* Data structures for mutex handling. The structure of the attribute
type is not exposed on purpose. */
typedef union
{
struct __pthread_mutex_s
{
int __lock;
unsigned int __count;
int __owner;
#if __WORDSIZE == 64
unsigned int __nusers;
#endif
/* KIND must stay at this position in the structure to maintain
binary compatibility. */
int __kind;
#if __WORDSIZE == 64
int __spins;
__pthread_list_t __list;
# define __PTHREAD_MUTEX_HAVE_PREV 1
#else
unsigned int __nusers;
__extension__ union
{
int __spins;
__pthread_slist_t __list;
};
#endif
} __data;
char __size[__SIZEOF_PTHREAD_MUTEX_T];
long int __align;
} pthread_mutex_t;
typedef union
{
char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
int __align;
} pthread_mutexattr_t;
/* Data structure for conditional variable handling. The structure of
the attribute type is not exposed on purpose. */
typedef union
{
struct
{
int __lock;
unsigned int __futex;
__extension__ unsigned long long int __total_seq;
__extension__ unsigned long long int __wakeup_seq;
__extension__ unsigned long long int __woken_seq;
void *__mutex;
unsigned int __nwaiters;
unsigned int __broadcast_seq;
} __data;
char __size[__SIZEOF_PTHREAD_COND_T];
__extension__ long long int __align;
} pthread_cond_t;
typedef union
{
char __size[__SIZEOF_PTHREAD_CONDATTR_T];
int __align;
} pthread_condattr_t;
/* Keys for thread-specific data */
typedef unsigned int pthread_key_t;
/* Once-only execution */
typedef int pthread_once_t;
#if defined __USE_UNIX98 || defined __USE_XOPEN2K
/* Data structure for read-write lock variable handling. The
structure of the attribute type is not exposed on purpose. */
typedef union
{
# if __WORDSIZE == 64
struct
{
int __lock;
unsigned int __nr_readers;
unsigned int __readers_wakeup;
unsigned int __writer_wakeup;
unsigned int __nr_readers_queued;
unsigned int __nr_writers_queued;
int __writer;
int __shared;
unsigned long int __pad1;
unsigned long int __pad2;
/* FLAGS must stay at this position in the structure to maintain
binary compatibility. */
unsigned int __flags;
} __data;
# else
struct
{
int __lock;
unsigned int __nr_readers;
unsigned int __readers_wakeup;
unsigned int __writer_wakeup;
unsigned int __nr_readers_queued;
unsigned int __nr_writers_queued;
/* FLAGS must stay at this position in the structure to maintain
binary compatibility. */
unsigned char __flags;
unsigned char __shared;
unsigned char __pad1;
unsigned char __pad2;
int __writer;
} __data;
# endif
char __size[__SIZEOF_PTHREAD_RWLOCK_T];
long int __align;
} pthread_rwlock_t;
typedef union
{
char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
long int __align;
} pthread_rwlockattr_t;
#endif
#ifdef __USE_XOPEN2K
/* POSIX spinlock data type. */
typedef volatile int pthread_spinlock_t;
/* POSIX barriers data type. The structure of the type is
deliberately not exposed. */
typedef union
{
char __size[__SIZEOF_PTHREAD_BARRIER_T];
long int __align;
} pthread_barrier_t;
typedef union
{
char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
int __align;
} pthread_barrierattr_t;
#endif
#if __WORDSIZE == 32
/* Extra attributes for the cleanup functions. */
# define __cleanup_fct_attribute __attribute__ ((__regparm__ (1)))
#endif
#endif /* bits/pthreadtypes.h */
==================================================
上面两个文件是不是一样的啊。
root@ubuntu:/usr/include/bits# diff pthreadtypes.h types.h >comparefile.txt
diff下,不会看这个结果。
1c1,2
< /* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc.
---
> /* bits/types.h -- definitions of __*_t types underlying *_t types.
> Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
3d3
< Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
20,21c20,22
< #ifndef _BITS_PTHREADTYPES_H
< #define _BITS_PTHREADTYPES_H 1
---
> /*
> * Never include this file directly; use <sys/types.h> instead.
> */
22a24,27
> #ifndef _BITS_TYPES_H
> #define _BITS_TYPES_H 1
>
> #include <features.h>
24a30,42
> /* Convenience types. */
> typedef unsigned char __u_char;
> typedef unsigned short int __u_short;
> typedef unsigned int __u_int;
> typedef unsigned long int __u_long;
>
> /* Fixed-size types, underlying types depend on word size and compiler. */
> typedef signed char __int8_t;
> typedef unsigned char __uint8_t;
> typedef signed short int __int16_t;
> typedef unsigned short int __uint16_t;
> typedef signed int __int32_t;
> typedef unsigned int __uint32_t;
26,44c44,48
< # define __SIZEOF_PTHREAD_ATTR_T 56
< # define __SIZEOF_PTHREAD_MUTEX_T 40
< # define __SIZEOF_PTHREAD_MUTEXATTR_T 4
< # define __SIZEOF_PTHREAD_COND_T 48
< # define __SIZEOF_PTHREAD_CONDATTR_T 4
< # define __SIZEOF_PTHREAD_RWLOCK_T 56
< # define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
< # define __SIZEOF_PTHREAD_BARRIER_T 32
< # define __SIZEOF_PTHREAD_BARRIERATTR_T 4
< #else
< # define __SIZEOF_PTHREAD_ATTR_T 36
< # define __SIZEOF_PTHREAD_MUTEX_T 24
< # define __SIZEOF_PTHREAD_MUTEXATTR_T 4
< # define __SIZEOF_PTHREAD_COND_T 48
< # define __SIZEOF_PTHREAD_CONDATTR_T 4
< # define __SIZEOF_PTHREAD_RWLOCK_T 32
< # define __SIZEOF_PTHREAD_RWLOCKATTR_T 8
< # define __SIZEOF_PTHREAD_BARRIER_T 20
< # define __SIZEOF_PTHREAD_BARRIERATTR_T 4
---
> typedef signed long int __int64_t;
> typedef unsigned long int __uint64_t;
> #elif defined __GLIBC_HAVE_LONG_LONG
> __extension__ typedef signed long long int __int64_t;
> __extension__ typedef unsigned long long int __uint64_t;
47,59c51
<
< /* Thread identifiers. The structure of the attribute type is not
< exposed on purpose. */
< typedef unsigned long int pthread_t;
<
<
< typedef union
< {
< char __size[__SIZEOF_PTHREAD_ATTR_T];
< long int __align;
< } pthread_attr_t;
<
<
---
> /* quad_t is also 64 bits. */
61,65c53,57
< typedef struct __pthread_internal_list
< {
< struct __pthread_internal_list *__prev;
< struct __pthread_internal_list *__next;
< } __pthread_list_t;
---
> typedef long int __quad_t;
> typedef unsigned long int __u_quad_t;
> #elif defined __GLIBC_HAVE_LONG_LONG
> __extension__ typedef long long int __quad_t;
> __extension__ typedef unsigned long long int __u_quad_t;
67c59
< typedef struct __pthread_internal_slist
---
> typedef struct
69,70c61,66
< struct __pthread_internal_slist *__next;
< } __pthread_slist_t;
---
> long __val[2];
> } __quad_t;
> typedef struct
> {
> __u_long __val[2];
> } __u_quad_t;
74,92c70,127
< /* Data structures for mutex handling. The structure of the attribute
< type is not exposed on purpose. */
< typedef union
< {
< struct __pthread_mutex_s
< {
< int __lock;
< unsigned int __count;
< int __owner;
< #if __WORDSIZE == 64
< unsigned int __nusers;
< #endif
< /* KIND must stay at this position in the structure to maintain
< binary compatibility. */
< int __kind;
< #if __WORDSIZE == 64
< int __spins;
< __pthread_list_t __list;
< # define __PTHREAD_MUTEX_HAVE_PREV 1
---
> /* The machine-dependent file <bits/typesizes.h> defines __*_T_TYPE
> macros for each of the OS types we define below. The definitions
> of those macros must use the following macros for underlying types.
> We define __S<SIZE>_TYPE and __U<SIZE>_TYPE for the signed and unsigned
> variants of each of the following integer types on this machine.
>
> 16 -- "natural" 16-bit type (always short)
> 32 -- "natural" 32-bit type (always int)
> 64 -- "natural" 64-bit type (long or long long)
> LONG32 -- 32-bit type, traditionally long
> QUAD -- 64-bit type, always long long
> WORD -- natural type of __WORDSIZE bits (int or long)
> LONGWORD -- type of __WORDSIZE bits, traditionally long
>
> We distinguish WORD/LONGWORD, 32/LONG32, and 64/QUAD so that the
> conventional uses of `long' or `long long' type modifiers match the
> types we define, even when a less-adorned type would be the same size.
> This matters for (somewhat) portably writing printf/scanf formats for
> these types, where using the appropriate l or ll format modifiers can
> make the typedefs and the formats match up across all GNU platforms. If
> we used `long' when it's 64 bits where `long long' is expected, then the
> compiler would warn about the formats not matching the argument types,
> and the programmer changing them to shut up the compiler would break the
> program's portability.
>
> Here we assume what is presently the case in all the GCC configurations
> we support: long long is always 64 bits, long is always word/address size,
> and int is always 32 bits. */
>
> #define __S16_TYPE short int
> #define __U16_TYPE unsigned short int
> #define __S32_TYPE int
> #define __U32_TYPE unsigned int
> #define __SLONGWORD_TYPE long int
> #define __ULONGWORD_TYPE unsigned long int
> #if __WORDSIZE == 32
> # define __SQUAD_TYPE __quad_t
> # define __UQUAD_TYPE __u_quad_t
> # define __SWORD_TYPE int
> # define __UWORD_TYPE unsigned int
> # define __SLONG32_TYPE long int
> # define __ULONG32_TYPE unsigned long int
> # define __S64_TYPE __quad_t
> # define __U64_TYPE __u_quad_t
> /* We want __extension__ before typedef's that use nonstandard base types
> such as `long long' in C89 mode. */
> # define __STD_TYPE __extension__ typedef
> #elif __WORDSIZE == 64
> # define __SQUAD_TYPE long int
> # define __UQUAD_TYPE unsigned long int
> # define __SWORD_TYPE long int
> # define __UWORD_TYPE unsigned long int
> # define __SLONG32_TYPE int
> # define __ULONG32_TYPE unsigned int
> # define __S64_TYPE long int
> # define __U64_TYPE unsigned long int
> /* No need to mark the typedef with __extension__. */
> # define __STD_TYPE typedef
94,99c129
< unsigned int __nusers;
< __extension__ union
< {
< int __spins;
< __pthread_slist_t __list;
< };
---
> # error
101,104c131
< } __data;
< char __size[__SIZEOF_PTHREAD_MUTEX_T];
< long int __align;
< } pthread_mutex_t;
---
> #include <bits/typesizes.h> /* Defines __*_T_TYPE macros. */
106,110d132
< typedef union
< {
< char __size[__SIZEOF_PTHREAD_MUTEXATTR_T];
< int __align;
< } pthread_mutexattr_t;
111a134,151
> __STD_TYPE __DEV_T_TYPE __dev_t; /* Type of device numbers. */
> __STD_TYPE __UID_T_TYPE __uid_t; /* Type of user identifications. */
> __STD_TYPE __GID_T_TYPE __gid_t; /* Type of group identifications. */
> __STD_TYPE __INO_T_TYPE __ino_t; /* Type of file serial numbers. */
> __STD_TYPE __INO64_T_TYPE __ino64_t; /* Type of file serial numbers (LFS).*/
> __STD_TYPE __MODE_T_TYPE __mode_t; /* Type of file attribute bitmasks. */
> __STD_TYPE __NLINK_T_TYPE __nlink_t; /* Type of file link counts. */
> __STD_TYPE __OFF_T_TYPE __off_t; /* Type of file sizes and offsets. */
> __STD_TYPE __OFF64_T_TYPE __off64_t; /* Type of file sizes and offsets (LFS). */
> __STD_TYPE __PID_T_TYPE __pid_t; /* Type of process identifications. */
> __STD_TYPE __FSID_T_TYPE __fsid_t; /* Type of file system IDs. */
> __STD_TYPE __CLOCK_T_TYPE __clock_t; /* Type of CPU usage counts. */
> __STD_TYPE __RLIM_T_TYPE __rlim_t; /* Type for resource measurement. */
> __STD_TYPE __RLIM64_T_TYPE __rlim64_t; /* Type for resource measurement (LFS). */
> __STD_TYPE __ID_T_TYPE __id_t; /* General type for IDs. */
> __STD_TYPE __TIME_T_TYPE __time_t; /* Seconds since the Epoch. */
> __STD_TYPE __USECONDS_T_TYPE __useconds_t; /* Count of microseconds. */
> __STD_TYPE __SUSECONDS_T_TYPE __suseconds_t; /* Signed count of microseconds. */
113,130c153,155
< /* Data structure for conditional variable handling. The structure of
< the attribute type is not exposed on purpose. */
< typedef union
< {
< struct
< {
< int __lock;
< unsigned int __futex;
< __extension__ unsigned long long int __total_seq;
< __extension__ unsigned long long int __wakeup_seq;
< __extension__ unsigned long long int __woken_seq;
< void *__mutex;
< unsigned int __nwaiters;
< unsigned int __broadcast_seq;
< } __data;
< char __size[__SIZEOF_PTHREAD_COND_T];
< __extension__ long long int __align;
< } pthread_cond_t;
---
> __STD_TYPE __DADDR_T_TYPE __daddr_t; /* The type of a disk address. */
> __STD_TYPE __SWBLK_T_TYPE __swblk_t; /* Type of a swap block maybe? */
> __STD_TYPE __KEY_T_TYPE __key_t; /* Type of an IPC key. */
132,136c157,158
< typedef union
< {
< char __size[__SIZEOF_PTHREAD_CONDATTR_T];
< int __align;
< } pthread_condattr_t;
---
> /* Clock ID used in clock and timer functions. */
> __STD_TYPE __CLOCKID_T_TYPE __clockid_t;
137a160,161
> /* Timer ID returned by `timer_create'. */
> __STD_TYPE __TIMER_T_TYPE __timer_t;
139,140c163,164
< /* Keys for thread-specific data */
< typedef unsigned int pthread_key_t;
---
> /* Type to represent block size. */
> __STD_TYPE __BLKSIZE_T_TYPE __blksize_t;
141a166
> /* Types from the Large File Support interface. */
143,144c168,170
< /* Once-only execution */
< typedef int pthread_once_t;
---
> /* Type to count number of disk blocks. */
> __STD_TYPE __BLKCNT_T_TYPE __blkcnt_t;
> __STD_TYPE __BLKCNT64_T_TYPE __blkcnt64_t;
145a172,174
> /* Type to count file system blocks. */
> __STD_TYPE __FSBLKCNT_T_TYPE __fsblkcnt_t;
> __STD_TYPE __FSBLKCNT64_T_TYPE __fsblkcnt64_t;
147,189c176,178
< #if defined __USE_UNIX98 || defined __USE_XOPEN2K
< /* Data structure for read-write lock variable handling. The
< structure of the attribute type is not exposed on purpose. */
< typedef union
< {
< # if __WORDSIZE == 64
< struct
< {
< int __lock;
< unsigned int __nr_readers;
< unsigned int __readers_wakeup;
< unsigned int __writer_wakeup;
< unsigned int __nr_readers_queued;
< unsigned int __nr_writers_queued;
< int __writer;
< int __shared;
< unsigned long int __pad1;
< unsigned long int __pad2;
< /* FLAGS must stay at this position in the structure to maintain
< binary compatibility. */
< unsigned int __flags;
< } __data;
< # else
< struct
< {
< int __lock;
< unsigned int __nr_readers;
< unsigned int __readers_wakeup;
< unsigned int __writer_wakeup;
< unsigned int __nr_readers_queued;
< unsigned int __nr_writers_queued;
< /* FLAGS must stay at this position in the structure to maintain
< binary compatibility. */
< unsigned char __flags;
< unsigned char __shared;
< unsigned char __pad1;
< unsigned char __pad2;
< int __writer;
< } __data;
< # endif
< char __size[__SIZEOF_PTHREAD_RWLOCK_T];
< long int __align;
< } pthread_rwlock_t;
---
> /* Type to count file system nodes. */
> __STD_TYPE __FSFILCNT_T_TYPE __fsfilcnt_t;
> __STD_TYPE __FSFILCNT64_T_TYPE __fsfilcnt64_t;
191,196c180
< typedef union
< {
< char __size[__SIZEOF_PTHREAD_RWLOCKATTR_T];
< long int __align;
< } pthread_rwlockattr_t;
< #endif
---
> __STD_TYPE __SSIZE_T_TYPE __ssize_t; /* Type of a byte count, or error. */
197a182,186
> /* These few don't really vary by system, they always correspond
> to one of the other defined types. */
> typedef __off64_t __loff_t; /* Type of file sizes and offsets (LFS). */
> typedef __quad_t *__qaddr_t;
> typedef char *__caddr_t;
199,201c188,189
< #ifdef __USE_XOPEN2K
< /* POSIX spinlock data type. */
< typedef volatile int pthread_spinlock_t;
---
> /* Duplicates info from stdint.h but this is used in unistd.h. */
> __STD_TYPE __SWORD_TYPE __intptr_t;
202a191,192
> /* Duplicate info from sys/socket.h. */
> __STD_TYPE __U32_TYPE __socklen_t;
204,210d193
< /* POSIX barriers data type. The structure of the type is
< deliberately not exposed. */
< typedef union
< {
< char __size[__SIZEOF_PTHREAD_BARRIER_T];
< long int __align;
< } pthread_barrier_t;
212,223c195
< typedef union
< {
< char __size[__SIZEOF_PTHREAD_BARRIERATTR_T];
< int __align;
< } pthread_barrierattr_t;
< #endif
<
<
< #if __WORDSIZE == 32
< /* Extra attributes for the cleanup functions. */
< # define __cleanup_fct_attribute __attribute__ ((__regparm__ (1)))
< #endif
---
> #undef __STD_TYPE
225c197
< #endif /* bits/pthreadtypes.h */
---
> #endif /* bits/types.h */
============================================================
diff命令的使用
摘要:本文详细介绍了diff命令的基本用法
作者:zieckey (zieckey@yahoo.com.cn)
All Rights Reserved!
有这样两个文件:
程序清单1 :hello.c
#include <stdio.h>
int main(void)
{
char msg[] = "Hello world!";
puts(msg);
printf("Welcome to use diff commond./n");
return 0;
}
程序清单2:hello_diff.c
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char msg[] = "Hello world,fome hello_diff.c";
puts(msg);
printf("hello_diff.c says,'Here you are,using diff.'/n");
return 0;
}
我们使用diff命令来查看这两个文件的不同之处,有一下几种方便的方法:
1、普通格式输出:
[root@localhost diff]# diff hello.c hello_diff.c
1a2
> #include <stdlib.h>
5c6
< char msg[] = "Hello world!";
---
> char msg[] = "Hello world,fome hello_diff.c";
8c9
< printf("Welcome to use diff commond./n");
---
> printf("hello_diff.c says,'Here you are,using diff.'/n");
[root@localhost diff]#
上面的“1a2”表示后面的一个文件"hello_diff.c"比前面的一个文件"hello.c"多了一行
"5c6"表示第一个文件的第5行与第二个文件的第6行有区别
2、并排格式输出
[root@localhost diff]# diff hello.c hello_diff.c -y -W 130
root@ubuntu:/usr/include/bits# diff pthreadtypes.h types.h -y -W 130>/home/zhangbin/code/comparefile1.txt
diff: option requires an argument -- 'W'
diff: Try `diff --help' for more information.
root@ubuntu:/usr/include/bits# diff pthreadtypes.h types.h -y -W 130 > /home/zhangbin/code/comparefile1.txt
是因为130后面,没有加上空格。
#include <stdio.h> #include <stdio.h>
> #include <stdlib.h>
int main(void) int main(void)
{ {
char msg[] = "Hello world!"; | char msg[] = "Hello world,fome hello_diff.c";
puts(msg); puts(msg);
printf("Welcome to use diff commond./n"); | printf("hello_diff.c says,'Here you are,using diff.'/
return 0; return 0;
} }
我运行的结果:
/* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software | /* bits/types.h -- definitions of __*_t types underlying *_t
> Copyright (C) 2002, 2003, 2004, 2005, 2007 Free Software F
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. <
The GNU C Library is free software; you can redistribute i The GNU C Library is free software; you can redistribute i
modify it under the terms of the GNU Lesser General Public modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; eith License as published by the Free Software Foundation; eith
version 2.1 of the License, or (at your option) any later version 2.1 of the License, or (at your option) any later
The GNU C Library is distributed in the hope that it will The GNU C Library is distributed in the hope that it will
but WITHOUT ANY WARRANTY; without even the implied warrant but WITHOUT ANY WARRANTY; without even the implied warrant
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
Lesser General Public License for more details. Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General You should have received a copy of the GNU Lesser General
License along with the GNU C Library; if not, write to the License along with the GNU C Library; if not, write to the
Software Foundation, Inc., 59 Temple Place, Suite 330, Bos Software Foundation, Inc., 59 Temple Place, Suite 330, Bos
02111-1307 USA. */ 02111-1307 USA. */
#ifndef _BITS_PTHREADTYPES_H | /*
#define _BITS_PTHREADTYPES_H 1 | * Never include this file directly; use <sys/types.h> instea
> */
> #ifndef _BITS_TYPES_H
> #define _BITS_TYPES_H 1
>
> #include <features.h>
#include <bits/wordsize.h> #include <bits/wordsize.h>
> /* Convenience types. */
> typedef unsigned char __u_char;
> typedef unsigned short int __u_short;
> typedef unsigned int __u_int;
> typedef unsigned long int __u_long;
>
> /* Fixed-size types, underlying types depend on word size and
> typedef signed char __int8_t;
> typedef unsigned char __uint8_t;
> typedef signed short int __int16_t;
> typedef unsigned short int __uint16_t;
> typedef signed int __int32_t;
> typedef unsigned int __uint32_t;
#if __WORDSIZE == 64 #if __WORDSIZE == 64
# define __SIZEOF_PTHREAD_ATTR_T 56 | typedef signed long int __int64_t;
# define __SIZEOF_PTHREAD_MUTEX_T 40 | typedef unsigned long int __uint64_t;
# define __SIZEOF_PTHREAD_MUTEXATTR_T 4 | #elif defined __GLIBC_HAVE_LONG_LONG
# define __SIZEOF_PTHREAD_COND_T 48 | __extension__ typedef signed long long int __int64_t;
# define __SIZEOF_PTHREAD_CONDATTR_T 4 | __extension__ typedef unsigned long long int __uint64_t;
# define __SIZEOF_PTHREAD_RWLOCK_T 56 <
# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8 <
# define __SIZEOF_PTHREAD_BARRIER_T 32 <
# define __SIZEOF_PTHREAD_BARRIERATTR_T 4 <
#else <
# define __SIZEOF_PTHREAD_ATTR_T 36 <
# define __SIZEOF_PTHREAD_MUTEX_T 24 <
# define __SIZEOF_PTHREAD_MUTEXATTR_T 4 <
# define __SIZEOF_PTHREAD_COND_T 48 <
# define __SIZEOF_PTHREAD_CONDATTR_T 4 <
# define __SIZEOF_PTHREAD_RWLOCK_T 32 <
# define __SIZEOF_PTHREAD_RWLOCKATTR_T 8 <
# define __SIZEOF_PTHREAD_BARRIER_T 20 <
# define __SIZEOF_PTHREAD_BARRIERATTR_T 4 <
#endif #endif
| /* quad_t is also 64 bits. */
/* Thread identifiers. The structure of the attribute type i <
exposed on purpose. */ <
typedef unsigned long int pthread_t; <
<
<
typedef union <
{ <
char __size[__SIZEOF_PTHREAD_ATTR_T]; <
long int __align; <
} pthread_attr_t; <
<
<
#if __WORDSIZE == 64 #if __WORDSIZE == 64
typedef struct __pthread_internal_list | typedef long int __quad_t;
{ | typedef unsigned long int __u_quad_t;
struct __pthread_internal_list *__prev; | #elif defined __GLIBC_HAVE_LONG_LONG
struct __pthread_internal_list *__next; | __extension__ typedef long long int __quad_t;
} __pthread_list_t; | __extension__ typedef unsigned long long int __u_quad_t;
#else #else
typedef struct __pthread_internal_slist | typedef struct
{ {
struct __pthread_internal_slist *__next; | long __val[2];
} __pthread_slist_t; | } __quad_t;
> typedef struct
> {
> __u_long __val[2];
> } __u_quad_t;
#endif #endif
/* Data structures for mutex handling. The structure of the | /* The machine-dependent file <bits/typesizes.h> defines __*_
type is not exposed on purpose. */ | macros for each of the OS types we define below. The defi
typedef union | of those macros must use the following macros for underlyi
{ | We define __S<SIZE>_TYPE and __U<SIZE>_TYPE for the signed
struct __pthread_mutex_s | variants of each of the following integer types on this ma
{ |
int __lock; | 16 -- "natural" 16-bit type (always shor
unsigned int __count; | 32 -- "natural" 32-bit type (always int)
int __owner; | 64 -- "natural" 64-bit type (long or lon
#if __WORDSIZE == 64 | LONG32 -- 32-bit type, traditionally long
unsigned int __nusers; | QUAD -- 64-bit type, always long long
#endif | WORD -- natural type of __WORDSIZE bits (i
/* KIND must stay at this position in the structure to ma | LONGWORD -- type of __WORDSIZE bits, tradition
binary compatibility. */ |
int __kind; | We distinguish WORD/LONGWORD, 32/LONG32, and 64/QUAD so th
#if __WORDSIZE == 64 | conventional uses of `long' or `long long' type modifiers
int __spins; | types we define, even when a less-adorned type would be th
__pthread_list_t __list; | This matters for (somewhat) portably writing printf/scanf
# define __PTHREAD_MUTEX_HAVE_PREV 1 | these types, where using the appropriate l or ll format mo
> make the typedefs and the formats match up across all GNU
> we used `long' when it's 64 bits where `long long' is expe
> compiler would warn about the formats not matching the arg
> and the programmer changing them to shut up the compiler w
> program's portability.
>
> Here we assume what is presently the case in all the GCC c
> we support: long long is always 64 bits, long is always wo
> and int is always 32 bits. */
>
> #define __S16_TYPE short int
> #define __U16_TYPE unsigned short int
> #define __S32_TYPE int
> #define __U32_TYPE unsigned int
> #define __SLONGWORD_TYPE long int
> #define __ULONGWORD_TYPE unsigned long int
> #if __WORDSIZE == 32
> # define __SQUAD_TYPE __quad_t
> # define __UQUAD_TYPE __u_quad_t
> # define __SWORD_TYPE int
> # define __UWORD_TYPE unsigned int
> # define __SLONG32_TYPE long int
> # define __ULONG32_TYPE unsigned long int
> # define __S64_TYPE __quad_t
> # define __U64_TYPE __u_quad_t
> /* We want __extension__ before typedef's that use nonstandar
> such as `long long' in C89 mode. */
> # define __STD_TYPE __extension__ typedef
> #elif __WORDSIZE == 64
> # define __SQUAD_TYPE long int
> # define __UQUAD_TYPE unsigned long int
> # define __SWORD_TYPE long int
> # define __UWORD_TYPE unsigned long int
> # define __SLONG32_TYPE int
> # define __ULONG32_TYPE unsigned int
> # define __S64_TYPE long int
> # define __U64_TYPE unsigned long int
> /* No need to mark the typedef with __extension__. */
> # define __STD_TYPE typedef
#else #else
unsigned int __nusers; | # error
__extension__ union <
{ <
int __spins; <
__pthread_slist_t __list; <
}; <
#endif #endif
} __data; | #include <bits/typesizes.h> /* Defines __*_T_TYPE macros.
char __size[__SIZEOF_PTHREAD_MUTEX_T]; <
long int __align; <
} pthread_mutex_t; <
typedef union <
{ <
char __size[__SIZEOF_PTHREAD_MUTEXATTR_T]; <
int __align; <
} pthread_mutexattr_t; <
> __STD_TYPE __DEV_T_TYPE __dev_t; /* Type of device num
> __STD_TYPE __UID_T_TYPE __uid_t; /* Type of user ident
> __STD_TYPE __GID_T_TYPE __gid_t; /* Type of group iden
> __STD_TYPE __INO_T_TYPE __ino_t; /* Type of file seria
> __STD_TYPE __INO64_T_TYPE __ino64_t; /* Type of file seria
> __STD_TYPE __MODE_T_TYPE __mode_t; /* Type of file attri
> __STD_TYPE __NLINK_T_TYPE __nlink_t; /* Type of file link
> __STD_TYPE __OFF_T_TYPE __off_t; /* Type of file sizes
> __STD_TYPE __OFF64_T_TYPE __off64_t; /* Type of file sizes
> __STD_TYPE __PID_T_TYPE __pid_t; /* Type of process id
> __STD_TYPE __FSID_T_TYPE __fsid_t; /* Type of file syste
> __STD_TYPE __CLOCK_T_TYPE __clock_t; /* Type of CPU usage
> __STD_TYPE __RLIM_T_TYPE __rlim_t; /* Type for resource
> __STD_TYPE __RLIM64_T_TYPE __rlim64_t; /* Type for resource
> __STD_TYPE __ID_T_TYPE __id_t; /* General type for I