コード例 #1
0
static int authenticate_to_floppyd(char fullauth, int sock, char *display, 
				   int protoversion)
{
	off_t filelen=0;
	Byte buf[16];
	const char *command[] = { "xauth", "xauth", "extract", "-", 0, 0 };
	char *xcookie = NULL;
	Dword errcode;
	int bytesRead;

	if (fullauth) {
		command[4] = display;

		filelen=strlen(display);
		filelen += 100;

		xcookie = (char *) safe_malloc(filelen+4);
		filelen = safePopenOut(command, xcookie+4, filelen);
		if(filelen < 1)
		    return AUTH_AUTHFAILED;
	}
	dword2byte(4,buf);
	dword2byte(protoversion,buf+4);
	write(sock, buf, 8);

	bytesRead = read_dword(sock);

	if (bytesRead != 4 && bytesRead != 12) {
		return AUTH_WRONGVERSION;
	}


	errcode = read_dword(sock);

	if (errcode != AUTH_SUCCESS) {
		return errcode;
	}


	if(bytesRead == 8) {
	    protoversion = read_dword(sock);
	    read_dword(sock);
	}
	
	fprintf(stderr, "Protocol Version=%d\n", protoversion);

	if (fullauth) {
		dword2byte(filelen, (Byte *) xcookie);
		write(sock, xcookie, filelen+4);

		if (read_dword(sock) != 4) {
			return AUTH_PACKETOVERSIZE;
		}

		errcode = read_dword(sock);
	}

	return errcode;

}
コード例 #2
0
static void write_dword(int handle, Dword parm) 
{
	Byte val[4];

	dword2byte(parm, val);

	write(handle, val, 4);
}
コード例 #3
0
static int write_dword(int handle, Dword parm)
{
	Byte val[4];

	dword2byte(parm, val);

	if(write(handle, val, 4) < 4)
		return -1;
	return 0;
}
コード例 #4
0
ファイル: File.cpp プロジェクト: bradc6/libmidi
  bool File::write()
  {
    ofstream fh(_path.c_str(),ios::out | ios::binary);
    if(!fh.is_open()) return false; //Error check
    
    DataBuffer headerData=_header->data();
    
    fh.write("MThd",4);
    fh.write((char*)dword2byte(headerData.size()),4);
    fh.write((char*)headerData.data(),headerData.size());
    
    for(int i=0;i<_header->numTracks();i++)
      {
	Track* track=_tracks[i];
	DataBuffer trackData=track->data();
	
	fh.write("MTrk",4);
	fh.write((char*)dword2byte(trackData.size()),4);
	fh.write((char*)trackData.data(),trackData.size());
      }
    
    fh.close();
    return true;   
  }