copyfiles() {
	writefile(TMPFILE);
	int page_number1 = -1;
	int page_number2 = -1;

	int *buf1, *buf2;

	int fd_inpfile, fd_finalfile;

	if ((fd_inpfile=PF_OpenFile(TMPFILE))<0){
		PF_PrintError("Error in opening file");
		exit(1);
	}

	if ((fd_finalfile=PF_OpenFile(FILE))<0){
		PF_PrintError("Error in opening file");
		exit(1);
	}

	//transferring contents of finalfile to tmpfile
	int i, error;
	for(i = 0 ; i < B_R ; i++) {
		// get the page page_number of each file
		if((error=PF_GetNextPage(fd_finalfile,&page_number1,&buf1))!= PFE_OK) {
			PF_PrintError("Error");
			exit(1);
		}
		if((error=PF_GetNextPage(fd_inpfile,&page_number2,&buf2))!= PFE_OK) {
			PF_PrintError("Error");
			exit(1);
		}

		*((int *)buf2) = *((int *)buf1);
		//printf("%d ", *((int *)buf2));

		if ((error=PF_UnfixPage(fd_finalfile,page_number1,TRUE))!= PFE_OK){
			PF_PrintError("unfix buffer\n");
			exit(1);
		}

		if ((error=PF_UnfixPage(fd_inpfile,page_number2,TRUE))!= PFE_OK){
			PF_PrintError("unfix buffer\n");
			exit(1);
		}
	}
	if ((error=PF_CloseFile(fd_inpfile))!= PFE_OK){
		PF_PrintError("Error in closing input file\n");
		exit(1);
	}

	if ((error=PF_CloseFile(fd_finalfile))!= PFE_OK){
		PF_PrintError("Error in closing temporary file\n");
		exit(1);
	}
}
Ejemplo n.º 2
0
/**
 * Interactively adjust the backlight on a device
 * 
 * @param  cols    The number of columns on the terminal
 * @param  device  The device on which to adjust backlight
 */
static void adjust(int cols, const char* device)
{
  int min, max, cur, step, init, i, d;
  size_t lendir;
  char* dir = alloca(PATH_MAX * sizeof(char));
  char* buf = alloca(256 * sizeof(char));
  
  *dir = 0;
  dir = strcat(dir, BACKLIGHT_DIR "/");
  dir = strcat(dir, device);
  dir = strcat(dir, "/");
  lendir = strlen(dir);
  
  /* Get brightness parameters */
  min = 0;
  if (readfile(buf, strcat(dir, "max_brightness")))
    return;
  max = atoi(unnl(buf));
  *(dir + lendir) = 0;
  if (readfile(buf, strcat(dir, "brightness")))
    return;
  cur = atoi(unnl(buf));
  
  if (max <= min)
    return; /* what the buck */
  
  step = (max - min) / 200 ?: 1;
  init = cur;
  
  P("\n\n\n\n\n");
  bars(min, max, init, cur, cols);
  
  while ((d = getchar()) != -1)
    switch (d)
      {
      case 'q':
      case '\n':
      case 4:
	P("");
	return;
	
      case 'A':
      case 'C':
	cur += step << 1;
	/* fall through */
      case 'B':
      case 'D':
	cur -= step;
	if (cur < min)  cur = min;
	if (cur > max)  cur = max;
	if (writefile(buf, cur, dir))
	  return;
	bars(min, max, init, cur, cols);
      }
}
Ejemplo n.º 3
0
/*copy a file*/
void docopy()
{
	char sname[7];
	char dname[7];
	char line[80];
	char file[12800];
	char dirsector[512];
	int index,i;

	/*prompt for the first file name*/
	printstring("Name of the source file? \0");
	readstring(line);
	for (i=0; i<6; i++)
	{
		sname[i]=line[i];
		if (line[i]==0xd)
			break;
	}
	sname[i]=0x0;

	/*make sure it exists - find the directory entry*/
	readsector(2,dirsector);
	index=findname(sname,dirsector);
	if (index==-1)
	{
		printstring("File not found\r\n\0");
		return;
	}

	/*read the source file*/
	readfile(sname,file);

	/*prompt for the destination file name*/
	printstring("Name of the destination file? \0");
	readstring(line);
	for (i=0; i<6; i++)
	{
		dname[i]=line[i];
		if (line[i]==0xd)
			break;
	}
	dname[i]=0x0;

	/*figure out how long the source file is*/
	i=0;
	index=index+6;
	while(dirsector[index]!=0x0)
	{
		index++;
		i++;
	}

	/*write the file*/
	writefile(dname,file,i);
}
Ejemplo n.º 4
0
int
main(void)
{
	writefile("/tmp/f1", "file1.txt");
	writefile("/tmp/f2", "file2.txt");
	writefile("/tmp/f3", "file3.txt");
	writefile("/tmp/f4", "file4.txt");
	writefile("/tmp/f5", "file5.txt");
	writefile("/tmp/f6", "file6.txt");
	writefile("/tmp/f7", "file7.txt");
	writefile("/tmp/f8", "file8.txt");
	return 0;
}
Ejemplo n.º 5
0
//-----------------------------------------------------------------------
// Add2Log - Add string to the the file
//
void Add2Log (TCHAR *lpszFormat, ...) {
    int nBuf;//, i;
    TCHAR szBuffer[512];

    va_list args;
    va_start(args, lpszFormat);

    nBuf = vswprintf(szBuffer, lpszFormat, args);
	writefile(szBuffer);
    va_end(args);
}
void callASort(T* buff, size_t size, T*(*asort)(T* buff, size_t n), LPCTSTR fileOut)
{
	T* forSort = duplicateBuff(buff, size);

	T* sortRes = asort(forSort, size);

	if (outputOutput)
		outputBuff(sortRes, size);

	writefile(fileOut, sortRes, size);
	delete[] forSort;
}
Ejemplo n.º 7
0
void dump2file (int signum) {
	static char filename[1024];
	if (!activevents) goto end;
	makename(filename);
	E("creat", creat(filename, 0666));
	// TODO I think creat() will always return 1 here.  Be sure.
	writefile();
	close(1);
	activevents = 0; // Removes all events.
 end:
	alarm(timeout);
	signal(SIGALRM, dump2file); }
Ejemplo n.º 8
0
bool Motor::writeMotorInt(const char *motorFile, int v)
{
	const size_t pathSize = MOTORPATHNAME_MAX;
	char path[pathSize];
	const size_t strsize = 30;
	char intstr[strsize];
	unsigned int n;

	snprintf(path, pathSize, "%s/%s", motorPath, motorFile);
	n = snprintf(intstr, strsize, "%d", v);
	return writefile(path, intstr, n);
}
Ejemplo n.º 9
0
// copy copies the file src to dst, via memory (so only good for small files).
static void
copy(char *dst, char *src, int exec)
{
	Buf b;

	if(vflag > 1)
		errprintf("cp %s %s\n", src, dst);

	binit(&b);
	readfile(&b, src);
	writefile(&b, dst, exec);
	bfree(&b);
}
Ejemplo n.º 10
0
void
ibs_stop(int cid)
{
    if (!ibs_enabled)
	return;
    cid = lcpu_to_pcpu[cid];
    char path[512];
    // set opctl to stop
    sprintf(path, "/sys/kernel/amd10h-ibs/cpu%d/opctl", cid);
    writefile(path, "0");
    sprintf(path, "/sys/kernel/amd10h-ibs/cpu%d/record", cid);
    readsamples(path);
}
Ejemplo n.º 11
0
int main(int argc, char **argv){

	if(argc != 3){
		printf("Error: invalid number of arguments\n");
		return -1;
	}
	
	if(strcmp(argv[1],argv[2])==0){
		printf("input arguments are the same file. Cannot overwrite. Exiting Indexer.\n");

		return 0;
	}

	int rval;
	char* output=argv[1];
	rval = access(output,F_OK);
	if(rval==0){
	//file exists
	}
	else if(errno==EACCES){
		printf("%s is not accessible\n", output);
		return 0;
	}

	rval = access(output, W_OK);
	if(rval==0){
		//permission to write
	}else if (errno==EACCES){
		printf("you do not have permission to write to %s\n",output);
		return 0;

	}

	struct List *list = SLCreate(); //create list to store words

	struct stat fileStat; //check if directory or file to be indexed exists
	if(stat(argv[2], &fileStat) == 0){

		directoryTraverse(list, argv[2]);


	}else{
		fprintf(stderr, "Directory or file you are trying to index does not exist.\n");	
		return -1;
	}	

	writefile(argv[1],list);
	destroyList(list);
	return 0;
}
Ejemplo n.º 12
0
Archivo: buildgc.c Proyecto: 8l/go
// gcopnames creates opnames.h from go.h.
// It finds the OXXX enum, pulls out all the constants
// from OXXX to OEND, and writes a table mapping
// op to string.
void
gcopnames(char *dir, char *file)
{
	char *p, *q;
	int i, j, end;
	Buf in, b, out;
	Vec lines, fields;
	
	binit(&in);
	binit(&b);
	binit(&out);
	vinit(&lines);
	vinit(&fields);
	
	bwritestr(&out, bprintf(&b, "// auto generated by go tool dist\n"));
	bwritestr(&out, bprintf(&b, "static char *opnames[] = {\n"));

	readfile(&in, bprintf(&b, "%s/go.h", dir));
	splitlines(&lines, bstr(&in));
	i = 0;
	while(i<lines.len && !contains(lines.p[i], "OXXX"))
		i++;
	end = 0;
	for(; i<lines.len && !end; i++) {
		p = xstrstr(lines.p[i], "//");
		if(p != nil)
			*p = '\0';
		end = contains(lines.p[i], "OEND");
		splitfields(&fields, lines.p[i]);
		for(j=0; j<fields.len; j++) {
			q = fields.p[j];
			if(*q == 'O')
				q++;
			p = q+xstrlen(q)-1;
			if(*p == ',')
				*p = '\0';
			bwritestr(&out, bprintf(&b, "	[O%s] = \"%s\",\n", q, q));
		}
	}
	
	bwritestr(&out, bprintf(&b, "};\n"));

	writefile(&out, file, 0);

	bfree(&in);
	bfree(&b);
	bfree(&out);
	vfree(&lines);
	vfree(&fields);
}
Ejemplo n.º 13
0
void update_cfgfile_parameters(struct DirectoryEntry *pDirEnt,unsigned char slot_index)
{
	cfgfile * cfgf;

	readfile(pDirEnt,0,0xc,0xd);

	cfgf=(cfgfile *)&sectorBuffer;
	cfgf->update_cnt++;
	cfgf->slot_index=slot_index;

	writefile(pDirEnt,0,0xc,0xd);

	return;
}
Ejemplo n.º 14
0
void test_odb_largefiles__streamwrite(void)
{
	git_oid expected, oid;

#ifndef GIT_ARCH_64
	cl_skip();
#endif

	if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE") ||
		!cl_is_env_set("GITTEST_SLOW"))
		cl_skip();

	git_oid_fromstr(&expected, "3fb56989cca483b21ba7cb0a6edb229d10e1c26c");
	writefile(&oid);

	cl_assert_equal_oid(&expected, &oid);
}
Ejemplo n.º 15
0
//将本地文件保存到远程,
int fileclient::putfile(const char *local_file_name, const char *remote_file_name)
{
	if(local_file_name == NULL || remote_file_name == NULL)
		return FILE_PARAM_ERROR;

    int len = 0;
    string name = _local_root + local_file_name;
    char *buffer = ReadFile(name.c_str() , len );
    if(buffer == NULL || len <= 0)
    {
    	return FILE_FAIL;
    }

    int ret = writefile(buffer, len, remote_file_name);
    free(buffer);
    return ret;
}
Ejemplo n.º 16
0
int main(int argc,char *argv[])
{
	int i;
	struct tuple t[NOFFILES][NOFWORDS];
	int sumoffreq[NOFFILES]; /* 빈도의 합계 */
    
	/* 명령행 인수 검사 */
	if (argc < 3) { /* 인수가 부족함 */
		fprintf(stderr, "사용법 tfidf "
                "(파일1) (파일2) ... \n");
		exit(1);
	}
	else if (argc > NOFFILES) { /* 파일이 너무 많음 */
		fprintf(stderr, "파일이 너무 많습니다(%d).\n "
				, argc);
		exit(1);
	}
    
    
	/* 파일에서 데이터 읽어오기 */
	for (i = 0; i < (argc - 1); ++i) {
		readfile(argv[i+1], t[i]);
	}
    
	/* 빈도 합계 계산 */
	for (i = 0; i < (argc - 1); ++i) {
		sumoffreq[i] = sumfreq(t[i]);
	}
    
	/* tf 값 계산 */
	for (i = 0; i < (argc - 1); ++i) {
		settf(t[i], sumoffreq[i]);
	}
    
	/* idf 값 계산 */
	for (i = 0; i < (argc - 1); ++i) {
		setidf(t, i, argc);
	}
    
	/* 파일에 데이터 기록하기 */
	for (i = 0; i < (argc - 1); ++i) {
		writefile(i, t[i]);
	}
    
	return 0;
}
Ejemplo n.º 17
0
void test_odb_largefiles__streamread(void)
{
	git_oid oid, read_oid;
	git_odb_stream *stream;
	char buf[10240];
	char hdr[64];
	size_t len, hdr_len, total = 0;
	git_hash_ctx hash;
	git_otype type;
	int ret;

#ifndef GIT_ARCH_64
	cl_skip();
#endif

	if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE") ||
		!cl_is_env_set("GITTEST_SLOW"))
		cl_skip();

	writefile(&oid);

	cl_git_pass(git_odb_open_rstream(&stream, &len, &type, odb, &oid));

	cl_assert_equal_sz(LARGEFILE_SIZE, len);
	cl_assert_equal_i(GIT_OBJ_BLOB, type);

	cl_git_pass(git_hash_ctx_init(&hash));
	cl_git_pass(git_odb__format_object_header(&hdr_len, hdr, sizeof(hdr), len, type));

	cl_git_pass(git_hash_update(&hash, hdr, hdr_len));

	while ((ret = git_odb_stream_read(stream, buf, 10240)) > 0) {
		cl_git_pass(git_hash_update(&hash, buf, ret));
		total += ret;
	}

	cl_assert_equal_sz(LARGEFILE_SIZE, total);

	git_hash_final(&read_oid, &hash);

	cl_assert_equal_oid(&oid, &read_oid);

	git_hash_ctx_cleanup(&hash);
	git_odb_stream_free(stream);
}
Ejemplo n.º 18
0
void fractal (options *opt) {
  double hx = (2*opt->r)/opt->width;
  double hy = (2*opt->r)/opt->height;
  int i, j, k;
  int s = 0;
  int max = 1;
  double scale = ((double)opt->width)/opt->height;
  FILE *S = fopen("sol.b","w");
  FILE *K = fopen("iters.b","w");
  double rx = opt->r, ry = opt->r;
  point p;

  if (scale > 1) {
    hx *= scale;
    rx *= scale;
  } else if (scale < 1) {
    hy /= scale;
    ry /= scale;
  }

  for (j = 0; j < opt->height; j++) {
    for (i = 0; i < opt->width; i++) {
      p.x = opt->cx - rx + i*hx;
      p.y = opt->cy - ry + j*hy;
#ifdef VERBOSE
      printf("C=(%lf,%lf), ", p.x, p.y);
#endif
      k = iterative_method(&p, opt);
      s = close_to_solution(&p, opt);
#ifdef VERBOSE
      printf("k = %d, s = %d\n", k, s);
#endif
      fprintf(S, "%d ", s);
      fprintf(K, "%d ", k);
      if (opt->simple == 0 && fabs(k) > max)
        max = fabs(k);
    }
  }
  fclose(S);
  fclose(K);

  printf("max = %d\n", max);

  writefile(max, opt);
}
Ejemplo n.º 19
0
const UCHAR *cmd_copy(const char *cmd)
{
	char nocmp = 0;
	cmd += *cmd + 2;
	if (optmatch(cmd, "nocmp")) {
		cmd += *cmd + 2;
		nocmp = 1;
	}
	if (optmatch(cmd, "from") == 0)
		errend(10); /* copy command error */
	readfile(pathfix(cmd + (4 + 2), 0), 0x0f);
	cmd += *cmd + 2;
	if (nocmp)
		len_filebuf = autodecomp2(SIZ_FILEBUF, filebuf0, len_filebuf);
	if (optmatch(cmd, "to") == 0)
		errend(10); /* copy command error */
	writefile(pathfix(cmd + (2 + 2), 1), 2, -1, 0x07);
	return cmd + (*cmd + 2);
}
Ejemplo n.º 20
0
static unsigned int protocol_write(struct service_backend *backend, struct service_state *state, void *buffer, unsigned int count)
{

    struct cpio_header header;

    if (!readheader(backend, &header, state->id))
        return 0;

    switch (header.mode & 0xF000)
    {

    case 0x8000:
        return writefile(backend, buffer, count, state->offset, state->id, &header);

    }

    return 0;

}
Ejemplo n.º 21
0
static unsigned int protocol_write(struct service_backend *backend, struct service_state *state, unsigned int id, unsigned int current, void *buffer, unsigned int count, unsigned int offset)
{

    struct cpio_header *header = mapheader(backend, state, id);

    if (!header)
        return 0;

    switch (header->mode & 0xF000)
    {

    case 0x8000:
        return writefile(backend, state, buffer, count, offset, id, header);

    }

    return 0;

}
Ejemplo n.º 22
0
void test_odb_largefiles__read_into_memory_rejected_on_32bit(void)
{
	git_oid oid;
	git_odb_object *obj = NULL;

#ifdef GIT_ARCH_64
	cl_skip();
#endif

	if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE") ||
		!cl_is_env_set("GITTEST_INVASIVE_MEMORY") ||
		!cl_is_env_set("GITTEST_SLOW"))
		cl_skip();

	writefile(&oid);
	cl_git_fail(git_odb_read(&obj, odb, &oid));

	git_odb_object_free(obj);
}
Ejemplo n.º 23
0
/*
 * set up all the config files
 */
static void
setup_config(void)
{
	char	  **conflines;
	char		repltok[100];
	char		path[MAXPGPATH];

	fputs(_("creating configuration files ... "), stdout);
	fflush(stdout);

	/* gtm.conf/gtm_proxy.conf */

	conflines = readfile(conf_file);

	/* Set options dedicated to both nodes */
	snprintf(repltok, sizeof(repltok), "nodename = '%s'", n_name);
	conflines = replace_token(conflines, "#nodename = ''", repltok);

	snprintf(repltok, sizeof(repltok), "port = %d", n_port);
	conflines = replace_token(conflines, "#port = 6666", repltok);

	if (is_gtm)
		snprintf(path, sizeof(path), "%s/gtm.conf", pg_data);
	else
	{
		/* Set options dedicated to Proxy */
		snprintf(repltok, sizeof(repltok), "gtm_host = '%s'", gtm_host);
		conflines = replace_token(conflines, "#gtm_host = ''", repltok);

		snprintf(repltok, sizeof(repltok), "gtm_port = %d", gtm_port);
		conflines = replace_token(conflines, "#gtm_port =", repltok);

		snprintf(path, sizeof(path), "%s/gtm_proxy.conf", pg_data);
	}

	writefile(path, conflines);
	chmod(path, S_IRUSR | S_IWUSR);

	free(conflines);

	check_ok();
}
Ejemplo n.º 24
0
// mkzgoos writes zgoos_$GOOS.go:
//
//	package runtime
//	const theGoos = <goos>
//
void
mkzgoos(char *dir, char *file)
{
	Buf b, out;
	
	binit(&b);
	binit(&out);
	
	bwritestr(&out, bprintf(&b,
		"// auto generated by go tool dist\n"
		"\n"
		"package runtime\n"
		"\n"
		"const theGoos = `%s`\n", goos));

	writefile(&out, file, 0);
	
	bfree(&b);
	bfree(&out);
}
Ejemplo n.º 25
0
void test_odb_largefiles__read_header(void)
{
	git_oid oid;
	size_t len;
	git_otype type;

#ifndef GIT_ARCH_64
	cl_skip();
#endif

	if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE") ||
		!cl_is_env_set("GITTEST_SLOW"))
		cl_skip();

	writefile(&oid);
	cl_git_pass(git_odb_read_header(&len, &type, odb, &oid));

	cl_assert_equal_sz(LARGEFILE_SIZE, len);
	cl_assert_equal_i(GIT_OBJ_BLOB, type);
}
Ejemplo n.º 26
0
// mkzversion writes zversion.go:
//
//	package runtime
//	const defaultGoroot = <goroot>
//	const theVersion = <version>
//
void
mkzversion(char *dir, char *file)
{
	Buf b, out;
	
	binit(&b);
	binit(&out);
	
	bwritestr(&out, bprintf(&b,
		"// auto generated by go tool dist\n"
		"\n"
		"package runtime\n"
		"\n"
		"const defaultGoroot = `%s`\n"
		"const theVersion = `%s`\n", goroot_final, goversion));

	writefile(&out, file, 0);
	
	bfree(&b);
	bfree(&out);
}
Ejemplo n.º 27
0
int main(void)
{
	int frames=pa_io();
	SAMPLE *recording;
	if(frames != -1)
	{
		int numSamples = frames * NUM_CHANNELS;
    		int numBytes = numSamples * sizeof(SAMPLE);
    		recording = (SAMPLE *) malloc( numBytes ); /* From now on, recordedSamples is initialised. */
    		if( recording == NULL )
    		{
        		printf("Could not allocate record array.\n");
        		goto done;
    		}
		int i;
    		for( i=0; i<numSamples; i++ ) recording[i] = 0;	
	}
	readfile(recording,frames);
	writefile(recording,frames);
#if 0
	{
		int x;
		for(x=10;x<=15;x++)
			printf(""PRINTF_S_FORMAT"\n",recording[x]);
	}		
#endif
	int numWindows = frames/1024,x=0;
	SAMPLE section[1024];
	fftw_complex *bins;
	bins=(fftw_complex*) fftw_malloc(sizeof(fftw_complex) * (1024/2+1));

	for(x=0;x<numWindows;x++)
	{	
		suba(recording,section,x*1024,(x*1024)+1024);
		mfft((double*)section,bins,1024);
	}
	fftw_free(bins);
done:
	return 0;
}
Ejemplo n.º 28
0
static void
reverse(Image *img, Image *tmp, int axis)
{
	Image *mask;
	Rectangle r;
	int i, d;

	/*
	 * We start by swapping large chunks at a time.
	 * The chunk size should be the largest power of
	 * two that fits in the dimension.
	 */
	d = axis==Xaxis ? Dx(img) : Dy(img);
	for(i = 1; i*2 <= d; i *= 2)
		;

	r = axis==Xaxis ? Rect(0,0, i,100) : Rect(0,0, 100,i);
	mask = xallocimage(display, r, GREY1, 1, DTransparent);
	mtmp = xallocimage(display, r, GREY1, 1, DTransparent);

	/*
	 * Now color the bottom (or left) half of the mask opaque.
	 */
	if(axis==Xaxis)
		r.max.x /= 2;
	else
		r.max.y /= 2;

	draw(mask, r, display->opaque, nil, ZP);
	writefile("mask", mask, i);

	/*
	 * Shuffle will recur, shuffling the pieces as necessary
	 * and making the mask a finer and finer grating.
	 */
	shuffle(img, tmp, axis, d, mask, i, 0);

	freeimage(mask);
}
Ejemplo n.º 29
0
void Add2LogWithTime(TCHAR *txt)
{
	BOOL bLogTime = TRUE;
	TCHAR str[512];
	TCHAR lpTimeStr[128];
	TCHAR lpDateStr[128];
	LONG res;
	wsprintf(str,L"");
	//Read the system time
	res = GetTimeFormat(LOCALE_SYSTEM_DEFAULT,
							TIME_FORCE24HOURFORMAT,
							NULL,
							L"hh:mm:ss",
							lpTimeStr,
							sizeof (lpTimeStr ) * sizeof(TCHAR));
	if (res == 0)
	{
		wcscpy(lpTimeStr, L"err");
	}

	//Read the system date
	res = GetDateFormat(  LOCALE_SYSTEM_DEFAULT,
						  NULL,
						  NULL,
						  L"dd.MM.yyyy",
						  lpDateStr,
						  sizeof (lpDateStr) * sizeof(TCHAR));
	if (res == 0)
	{
		wcscpy(lpDateStr, L"err");
	}

	if (bLogTime == TRUE)
		wsprintf(str, L"%s %s\t%s", lpDateStr, lpTimeStr , txt);
	else
		wsprintf(str, L"%s", txt);
	writefile(str);

}
Ejemplo n.º 30
0
// dopack copies the package src to dst,
// appending the files listed in extra.
// The archive format is the traditional Unix ar format.
static void
dopack(char *dst, char *src, char **extra, int nextra)
{
	int i;
	char c, *p, *q;
	Buf b, bdst;
	
	binit(&b);
	binit(&bdst);

	readfile(&bdst, src);
	for(i=0; i<nextra; i++) {
		readfile(&b, extra[i]);
		// find last path element for archive member name
		p = xstrrchr(extra[i], '/');
		if(p)
			p++;
		q = xstrrchr(extra[i], '\\');
		if(q) {
			q++;
			if(p == nil || q > p)
				p = q;
		}
		if(p == nil)
			p = extra[i];
		bwritef(&bdst, "%-16.16s%-12d%-6d%-6d%-8o%-10d`\n", p, 0, 0, 0, 0644, b.len);
		bwriteb(&bdst, &b);
		if(b.len&1) {
			c = 0;
			bwrite(&bdst, &c, 1);
		}
	}

	writefile(&bdst, dst, 0);

	bfree(&b);
	bfree(&bdst);
}