Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
17
Добавлен:
01.05.2014
Размер:
1.69 Кб
Скачать
	#ifndef DEVFILE_H	/* This is devfile.h header */

	#define DEVFILE_H

	#include	"regfile.h"

	

		/* A class to encapsulate POSIX and UNIX device files' properties */

	class devfile	:	public regfile 	

	{

		public:

			devfile(const char* fn, int flags, int prot) : regfile(fn,flags,prot)					{};

			int create2( const char* fn, mode_t prot, int major_no, int minor_no,

					char type='c')			

			{	if (type=='c')

					return mknod(fn, S_IFCHR | prot, 

							(major_no << 8) | minor_no);	

				else 	return mknod(fn, S_IFBLK | prot,

							(major_no << 8) | minor_no);

			};

			streampos tellg()			{ 	if (file_type()==CHAR_FILE)

								return (streampos)-1;

							else return fstream::tellg();	

						};

			istream& seekg( streampos ofs, seek_dir d)

						{ 	if (file_type()!=CHAR_FILE)

								fstream::seekg(ofs,d);

							return *this;

						};

			int lock( int lck_type, off_t len, int cmd=F_SETLK)			

						{	if (file_type()!=CHAR_FILE)

								return 

									regfile::lock(lck_type,len,cmd);

							else return -1;

						};

			int lockw( int lck_type, off_t len)			

						{	if (file_type()!=CHAR_FILE)

								return 

									regfile::lockw(lck_type,len);

							else return -1;

						};

			int unlock( off_t len)			{	if (file_type()!=CHAR_FILE)

								return regfile::unlock(len);

							else return -1;

						};

			int getlock( int lck_type, off_t len, struct flock& flck)			

						{	if (file_type()!=CHAR_FILE)

								return

								regfile::getlock(lck_type,len,flck);

							else return -1;

						};

			};

			#endif		/* devfile.h */
Соседние файлы в папке ch7