Update to nosefart from 2.3 to 2.7. Includes support for sndio, and
patches for snprintf, strlcat, strlcpy.
Index: Makefile
===================================================================
RCS file: /cvs/ports/audio/nosefart/Makefile,v
retrieving revision 1.2
diff -r1.2 Makefile
5,6c5,6
< DISTNAME=	nosefart-2.3-mls
< PKGNAME=	nosefart-2.3
---
> PKGNAME=	nosefart-2.7
> DISTNAME=	${PKGNAME}-mls
10c10
< MAINTAINER=	Matt Jibson <[email protected]>
---
> MAINTAINER=	Matt Jibson <[email protected]>
24c24
< WANTLIB=	m c ossaudio
---
> WANTLIB=	m c sndio
29d28
< 
Index: distinfo
===================================================================
RCS file: /cvs/ports/audio/nosefart/distinfo,v
retrieving revision 1.2
diff -r1.2 distinfo
1,5c1,5
< MD5 (nosefart-2.3-mls.tar.bz2) = icDlm7OrVipkdlPJCzqO0Q==
< RMD160 (nosefart-2.3-mls.tar.bz2) = VDZar1QtdvcmqbnrsNk6eiGcLl4=
< SHA1 (nosefart-2.3-mls.tar.bz2) = q1dVZ0re+j9vY+B3IkWDHnwL4vc=
< SHA256 (nosefart-2.3-mls.tar.bz2) = sjrSbDgaN40zkrSuaCsdPBLmmBrZF3FRMI0Hjd5byZo=
< SIZE (nosefart-2.3-mls.tar.bz2) = 531605
---
> MD5 (nosefart-2.7-mls.tar.bz2) = 9bOiA3ssWFG1BomPwffWvA==
> RMD160 (nosefart-2.7-mls.tar.bz2) = 8rfg1DOlfLxuAYtnVbmNMigCBUI=
> SHA1 (nosefart-2.7-mls.tar.bz2) = gz99i3mi1G+Pw+DqiqqJEkm9sQU=
> SHA256 (nosefart-2.7-mls.tar.bz2) = DcwFjeI1I1ltiq7hboI5RMgILDCLnbyXy9Yb50xhD4E=
> SIZE (nosefart-2.7-mls.tar.bz2) = 558745
Index: patches/patch-Makefile
===================================================================
RCS file: /cvs/ports/audio/nosefart/patches/patch-Makefile,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 patch-Makefile
1,3c1,3
< $OpenBSD: patch-Makefile,v 1.1.1.1 2005/03/08 14:36:26 niallo Exp $
< --- Makefile.orig	Fri Aug 13 01:19:33 2004
< +++ Makefile	Tue Mar  8 14:12:12 2005
---
> $OpenBSD$
> --- Makefile.orig	Thu Dec 13 21:46:22 2007
> +++ Makefile	Tue Jan 20 00:45:00 2009
13c13
< +LDFLAGS = -lm -lossaudio
---
> +LDFLAGS = -lm -lsndio
Index: patches/patch-src_linux_main_linux_c
===================================================================
RCS file: /cvs/ports/audio/nosefart/patches/patch-src_linux_main_linux_c,v
retrieving revision 1.1.1.1
diff -r1.1.1.1 patch-src_linux_main_linux_c
1,4c1,6
< $OpenBSD: patch-src_linux_main_linux_c,v 1.1.1.1 2005/03/08 14:36:26 niallo Exp $
< --- src/linux/main_linux.c.orig	Fri Mar  4 10:57:15 2005
< +++ src/linux/main_linux.c	Fri Mar  4 10:57:46 2005
< @@ -17,8 +17,9 @@ UNIX systems */
---
> $OpenBSD$
> --- src/linux/main_linux.c.orig	Sun Feb 10 12:39:29 2008
> +++ src/linux/main_linux.c	Wed Jan 21 00:56:33 2009
> @@ -15,10 +15,7 @@ UNIX systems */
>  #include <termios.h>
>  #include <unistd.h>
6,7c8,9
<  #include <sys/ioctl.h>
<  #include <sys/types.h>
---
> -#include <sys/ioctl.h>
> -#include <sys/types.h>
9,11c11,12
< +#include <soundcard.h>
<  #include <sys/stat.h>
< +#include <signal.h>
---
> -#include <sys/stat.h>
> +#include <sndio.h>
15,18c16,76
< @@ -223,7 +224,7 @@ static void open_hardware(const char *de
<     doesn't show up as a char device. The original author (Matthew Conte) seems
<     to have thought that esddsp should work without this hack.  Is doing this 
<     bad? --Matthew Strait */
---
> @@ -54,8 +51,8 @@ static int bits = 8;
>  /* sound */
>  static int dataSize;
>  static int bufferSize;
> -static unsigned char *buffer = 0, *bufferPos = 0;
> -static int audiofd;
> +static unsigned char *buffer = 0, *bufferPos = 0, *chbuffer;
> +static struct sio_hdl *hdl;
>  
>  static int * plimit_frames = NULL;
>  static int shm_id;
> @@ -180,123 +177,54 @@ void handle_auto_calc(char * filename, int track, int 
>  		*plimit_frames = get_time(reps, filename, track);
>  }
>  
> -/* HAS ROOT PERMISSIONS -- BE CAREFUL */
> -/* Open up the DSP, then drop the root permissions */
> +/* Open up the DSP */
>  static void open_hardware(const char *device)
>  {
> -   struct stat status;
> -
> -   /* Open the file (with root permissions, if we have them) */
> -   if(-1 == (audiofd = open(device, O_WRONLY, 0)))
> +   /* Open the file */
> +   if(NULL == (hdl = sio_open(device, SIO_PLAY, 0)))
>     {
> -      switch(errno)
> -      {
> -      case EBUSY:
> -         printf("%s is busy.\n", device);
> -         exit(1);
> -      default:
> -         printf("Unable to open %s.  Check the permissions.\n", device);
> -         exit(1);
> -      }
> -   }
> -
> -   /* For safety, we should check that device is, in fact, a device.
> -      `nosefart -d /etc/passwd MegaMan2.nsf` wouldn't sound so pretty. */
> -   if(-1 == fstat(audiofd, &status))
> -   {
> -      switch(errno)
> -      {
> -      case EFAULT:
> -      case ENOMEM:
> -         printf("Out of memory.\n");
> -         exit(1);
> -      case EBADF:
> -      case ELOOP:
> -      case EACCES:
> -      default:
> -         printf("Unable to stat %s.\n", device);
> -         exit(1);
> -      }
> -   }
> -   /* if it's not a char device and it's not /dev/dsp */
> -   /* The second check is because when run with esddsp, /dev/dsp
> -   doesn't show up as a char device. The original author (Matthew Conte) seems
> -   to have thought that esddsp should work without this hack.  Is doing this 
> -   bad? --Matthew Strait */
20c78,152
< +   if( !S_ISCHR(status.st_mode) && strcmp("/dev/audio", device))
---
> -   {
> -      printf("%s is not a character device.\n", device);
> +      printf("Unable to open sndio device %s.\n", device);
>        exit(1);
>     }
> -
> -   /* Drop root permissions */
> -   if(geteuid() != getuid()) setuid(getuid());
>  }
>  
>  /* Configure the DSP */
>  static void init_hardware(void)
>  {
> -   int stereo = 0;
> -   int param, retval, logDataSize;
> -   int format;
> -   
> -   switch(bits)
> -   {
> -   case 8:
> -      format = AFMT_U8;
> -      break;
> -   case 16:
> -      format = AFMT_S16_NE;
> -      break;
> -   default:
> -      printf("Bad sample depth: %i\n", bits);
> -      exit(1);
> -   }
> -   
> +   struct sio_par par;
> +
>     /* sound buffer */
>     dataSize = freq / nsf->playback_rate * (bits / 8);
>  
>     /* Configure the DSP */
> -   logDataSize = -1;
> -   while((1 << ++logDataSize) < dataSize);
> -   param = 0x10000 | logDataSize + 4;
> -   retval = ioctl(audiofd, SNDCTL_DSP_SETFRAGMENT, &param);
> -   if(-1 == retval)
> +   sio_initpar(&par);
> +   par.sig = bits == 16;
> +   par.pchan = 2;
> +   par.bits = bits;
> +   par.rate = freq;
> +
> +   if(!sio_setpar(hdl, &par))
>     {
> -      printf("Unable to set buffer size\n");
> -   }
> -   param = stereo;
> -   retval = ioctl(audiofd, SNDCTL_DSP_STEREO, &param);
> -   if(retval == -1 || param != stereo)
> -   {
> -      printf("Unable to set audio channels.\n");
> +      printf("Unable to set sndio parameters.\n");
>        exit(1);
>     }
> -   param = format;
> -   retval = ioctl(audiofd, SNDCTL_DSP_SETFMT, &param);
> -   if(retval == -1 || param != format)
> +
> +   if(!sio_getpar(hdl, &par))
>     {
> -      printf("Unable to set audio format.\n");
> -      printf("Wanted %i, got %i\n", format, param);
> +      printf("Unable to get sndio parameters.\n");
>        exit(1);
>     }
> -   param = freq;
> -   retval = ioctl(audiofd, SNDCTL_DSP_SPEED, &param);
> -   if(retval == -1 || (abs (param - freq) > (freq / 10)))
> +
> +   if(!sio_start(hdl))
22c154,156
<        printf("%s is not a character device.\n", device);
---
> -      printf("Unable to set audio frequency.\n");
> -      printf("Wanted %i, got %i\n", freq, param);
> +      printf("Unable to start sndio.\n");
24c158,183
< @@ -305,7 +306,7 @@ static void show_help(void)
---
>     }
> -   retval = ioctl(audiofd, SNDCTL_DSP_GETBLKSIZE, &param);
> -   if(-1 == retval)
> -   {
> -      printf("Unable to get buffer size\n");
> -      exit(1);
> -   }
> +
>     /* set up our data buffer */
> -   bufferSize = param;
> +   bufferSize = par.bufsz;
>     buffer = malloc((bufferSize / dataSize + 1) * dataSize);
> +   chbuffer = malloc((bufferSize / dataSize + 1) * dataSize);
>     bufferPos = buffer;
>     memset(buffer, 0, bufferSize);
>  }
> @@ -304,7 +232,7 @@ static void init_hardware(void)
>  /* close what we've opened */
>  static void close_hardware(void)
>  {
> -   close(audiofd);
> +   sio_close(hdl);
>     free(buffer);
>     buffer = 0;
>     bufferSize = 0;
> @@ -319,7 +247,7 @@ static void show_help(void)
29c188
< +   printf("\n\t-d x\tUse device x (default: /dev/audio)\n");
---
> +   printf("\n\t-d x\tUse device x (default: sndio default (NULL))\n");
32,34c191,228
<     printf("\t-l x\tLimit total playing time to x seconds (0 = unlimited)\n");
< @@ -565,7 +566,7 @@ static void close_nsf_file(void)
<  /* HAS ROOT PERMISSIONS -- BE CAREFUL */
---
>     printf("\t-B x\tUse sample size of x bits (default: 8)\n");
> @@ -516,6 +444,7 @@ static void play(char * filename, int track, int doaut
>  {
>     int done = 0;
>     int starting_time = time(NULL) - 1; /* the 1 helps with rounding error */
> +   int size, pos_buffer, pos_chbuffer;
>     frames = 0;
>  
>     /* determine which track to play */
> @@ -554,7 +483,22 @@ static void play(char * filename, int track, int doaut
>        if(bufferPos >= buffer + bufferSize)
>        {
>           if(frames >= starting_frame)
> -           write(audiofd, buffer, bufferPos - buffer);
> +         {
> +            /* simulate two channels */
> +            size = bufferPos - buffer;
> +            for(pos_buffer = 0, pos_chbuffer = 0; pos_chbuffer < size; pos_buffer++)
> +            {
> +               chbuffer[pos_chbuffer++] = buffer[pos_buffer];
> +               chbuffer[pos_chbuffer++] = buffer[pos_buffer];
> +            }
> +            sio_write(hdl, chbuffer, size);
> +            for(pos_chbuffer = 0; pos_buffer < size; pos_buffer++)
> +            {
> +               chbuffer[pos_chbuffer++] = buffer[pos_buffer];
> +               chbuffer[pos_chbuffer++] = buffer[pos_buffer];
> +            }
> +            sio_write(hdl, chbuffer, size);
> +         }
>           bufferPos = buffer;
>        }
>  
> @@ -578,10 +522,9 @@ static void close_nsf_file(void)
>     nsf = 0;
>  }
>  
> -/* HAS ROOT PERMISSIONS -- BE CAREFUL */
38c232
< +   char *device = "/dev/audio";
---
> +   char *device = NULL;
41a236,261
> @@ -613,7 +556,7 @@ int main(int argc, char **argv)
>           break;
>        case 'd':
>           device = malloc( strlen(optarg) + 1 );
> -         strcpy(device, optarg);
> +         strlcpy(device, optarg, strlen(optarg) + 1);
>           break;
>        case 't':
>           track = strtol(optarg, 0, 10);
> @@ -661,7 +604,7 @@ int main(int argc, char **argv)
>     if(argc <= optind)
>     show_help();
>     filename = malloc( strlen(argv[optind]) + 1 );
> -   strcpy(filename, argv[optind]);
> +   strlcpy(filename, argv[optind], strlen(argv[optind]) + 1);
>  
>     if(doautocalc)
>     {
> @@ -670,7 +613,6 @@ int main(int argc, char **argv)
>  
>  	handle_auto_calc(filename, track, reps);
>     }
> -   /* open_hardware uses, then discards, root permissions */
>     if(!justdisplayinfo) 
>  	open_hardware(device);
>  
Index: patches/patch-src_machine_nsf_c
===================================================================
RCS file: patches/patch-src_machine_nsf_c
diff -N patches/patch-src_machine_nsf_c
0a1,23
> $OpenBSD$
> --- src/machine/nsf.c.orig	Thu Dec 13 21:46:22 2007
> +++ src/machine/nsf.c	Tue Jan 20 01:59:00 2009
> @@ -517,8 +517,8 @@ static int nfs_open_file(struct nsf_loader_t *loader)
>        return -1;
>      }
>      /* try with .nsf extension. */
> -    strcpy(fname, floader->fname);
> -    strcat(fname, ".nsf");
> +    strlcpy(fname, floader->fname, strlen(floader->fname) + 5);
> +    strlcat(fname, ".nsf", strlen(floader->fname) + 5);
>      floader->fp = fopen(fname,"rb");
>      if (!floader->fp) {
>        free(fname);
> @@ -606,7 +606,7 @@ static int nfs_open_mem(struct nsf_loader_t *loader)
>      return -1;
>    }
>    mloader->cur = 0;
> -  sprintf(mloader->fname,"<mem(%p,%u)>",
> +  snprintf(mloader->fname, sizeof(mloader->fname), "<mem(%p,%u)>",
>  	  mloader->data, (unsigned int)mloader->len);
>    return 0;
>  }
Index: patches/patch-src_memguard_c
===================================================================
RCS file: patches/patch-src_memguard_c
diff -N patches/patch-src_memguard_c
0a1,21
> $OpenBSD$
> --- src/memguard.c.orig	Thu Dec 13 21:46:22 2007
> +++ src/memguard.c	Tue Jan 20 00:55:03 2009
> @@ -246,7 +246,7 @@ void *_my_malloc(int size)
>        sprintf(fail, "malloc: out of memory at line %d of %s.  block size: %d\n",
>                line, file, size);
>  #else
> -      sprintf(fail, "malloc: out of memory.  block size: %d\n", size);
> +      snprintf(fail, sizeof(fail), "malloc: out of memory.  block size: %d\n", size);
>  #endif
>        ASSERT_MSG(fail);
>     }
> @@ -277,7 +277,7 @@ void _my_free(void **data)
>        sprintf(fail, "free: attempted to free NULL pointer at line %d of %s\n",
>                line, file);
>  #else
> -      sprintf(fail, "free: attempted to free NULL pointer.\n");
> +      snprintf(fail, sizeof(fail), "free: attempted to free NULL pointer.\n");
>  #endif
>        ASSERT_MSG(fail);
>     }

Reply via email to