The patch number 7929 was added via Hans Verkuil <[EMAIL PROTECTED]>
to http://linuxtv.org/hg/v4l-dvb master development tree.

Kernel patches in this development tree may be modified to be backward
compatible with older kernels. Compatibility modifications will be
removed before inclusion into the mainstream Kernel

If anyone has any objections, please let us know by sending a message to:
        [EMAIL PROTECTED]

------

From: Hans Verkuil  <[EMAIL PROTECTED]>
v4l2-ctl: return errors as the program result


If an error occurs, then the program now returns an error. Also did a
few cleanups.

Signed-off-by: Hans Verkuil <[EMAIL PROTECTED]>


---

 v4l2-apps/util/v4l2-ctl.cpp |  119 +++++++++++++-----------------------
 1 file changed, 44 insertions(+), 75 deletions(-)

diff -r 8f8d9bea7443 -r a1a4bd572133 v4l2-apps/util/v4l2-ctl.cpp
--- a/v4l2-apps/util/v4l2-ctl.cpp       Wed May 21 19:40:19 2008 +0200
+++ b/v4l2-apps/util/v4l2-ctl.cpp       Sat May 24 13:02:27 2008 +0200
@@ -122,6 +122,8 @@ enum Option {
 };
 
 static char options[OptLast];
+
+static int app_result;
 
 static unsigned capabilities;
 
@@ -715,7 +717,7 @@ static void printcropcap(const struct v4
        printf("\tPixel Aspect: %u/%u\n", cropcap.pixelaspect.numerator, 
cropcap.pixelaspect.denominator);
 }
 
-static int printfmt(struct v4l2_format vfmt)
+static void printfmt(struct v4l2_format vfmt)
 {
        const flag_def vbi_def[] = {
                { V4L2_VBI_UNSYNC,     "unsynchronized" },
@@ -776,10 +778,7 @@ static int printfmt(struct v4l2_format v
                break;
        case V4L2_BUF_TYPE_PRIVATE:
                break;
-       default:
-               return -1;
-       }
-       return 0;
+       }
 }
 
 static void print_video_formats(int fd, enum v4l2_buf_type type)
@@ -999,10 +998,12 @@ static v4l2_std_id parse_ntsc(const char
 
 static int doioctl(int fd, int request, void *parm, const char *name)
 {
-       int retVal;
-
-       if (!options[OptVerbose]) return ioctl(fd, request, parm);
-       retVal = ioctl(fd, request, parm);
+       int retVal = ioctl(fd, request, parm);
+
+       if (retVal < 0) {
+               app_result = -1;
+       }
+       if (!options[OptVerbose]) return retVal;
        printf("%s: ", name);
        if (retVal < 0)
                printf("failed: %s\n", strerror(errno));
@@ -1068,9 +1069,7 @@ static void do_crop(int fd, unsigned int
     struct v4l2_crop in_crop;
 
     in_crop.type = type;
-    if (ioctl(fd, VIDIOC_G_CROP, &in_crop) < 0)
-       fprintf(stderr, "ioctl: VIDIOC_G_CROP failed\n");
-    else {
+    if (doioctl(fd, VIDIOC_G_CROP, &in_crop, "VIDIOC_G_CROP") == 0) {
        if (set_crop & CropWidth)
            in_crop.c.width = vcrop.width;
        if (set_crop & CropHeight)
@@ -1079,8 +1078,7 @@ static void do_crop(int fd, unsigned int
            in_crop.c.left = vcrop.left;
        if (set_crop & CropTop)
            in_crop.c.top = vcrop.top;
-       if (ioctl(fd, VIDIOC_S_CROP, &in_crop) < 0)
-           fprintf(stderr, "ioctl: VIDIOC_S_CROP failed\n");
+       doioctl(fd, VIDIOC_S_CROP, &in_crop, "VIDIOC_S_CROP");
     }
 }
 
@@ -1603,43 +1601,35 @@ int main(int argc, char **argv)
                struct v4l2_tuner vt;
 
                memset(&vt, 0, sizeof(struct v4l2_tuner));
-               if (ioctl(fd, VIDIOC_G_TUNER, &vt) < 0) {
-                       fprintf(stderr, "ioctl: VIDIOC_G_TUNER failed\n");
-                       exit(1);
-               }
-               vt.audmode = mode;
-               doioctl(fd, VIDIOC_S_TUNER, &vt, "VIDIOC_S_TUNER");
+               if (doioctl(fd, VIDIOC_G_TUNER, &vt, "VIDIOC_G_TUNER") == 0) {
+                       vt.audmode = mode;
+                       doioctl(fd, VIDIOC_S_TUNER, &vt, "VIDIOC_S_TUNER");
+               }
        }
 
        if (options[OptSetVideoFormat]) {
                struct v4l2_format in_vfmt;
-               printf("ioctl: VIDIOC_S_FMT\n");
+
                in_vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-               if (ioctl(fd, VIDIOC_G_FMT, &in_vfmt) < 0)
-                       fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n");
-               else {
+               if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt, "VIDIOC_G_FMT") == 0) {
                        if (set_fmts & FmtWidth)
                                in_vfmt.fmt.pix.width = vfmt.fmt.pix.width;
                        if (set_fmts & FmtHeight)
                                in_vfmt.fmt.pix.height = vfmt.fmt.pix.height;
-                       if (ioctl(fd, VIDIOC_S_FMT, &in_vfmt) < 0)
-                               fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n");
+                       doioctl(fd, VIDIOC_S_FMT, &in_vfmt, "VIDIOC_S_FMT");
                }
        }
 
        if (options[OptSetVideoOutFormat]) {
                struct v4l2_format in_vfmt;
-               printf("ioctl: VIDIOC_S_FMT\n");
+
                in_vfmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-               if (ioctl(fd, VIDIOC_G_FMT, &in_vfmt) < 0)
-                       fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n");
-               else {
+               if (doioctl(fd, VIDIOC_G_FMT, &in_vfmt, "VIDIOC_G_FMT") == 0) {
                        if (set_fmts_out & FmtWidth)
                                in_vfmt.fmt.pix.width = vfmt_out.fmt.pix.width;
                        if (set_fmts_out & FmtHeight)
                                in_vfmt.fmt.pix.height = 
vfmt_out.fmt.pix.height;
-                       if (ioctl(fd, VIDIOC_S_FMT, &in_vfmt) < 0)
-                               fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n");
+                       doioctl(fd, VIDIOC_S_FMT, &in_vfmt, "VIDIOC_S_FMT");
                }
        }
 
@@ -1669,29 +1659,24 @@ int main(int argc, char **argv)
 
        if (options[OptSetOutputOverlayFormat]) {
                struct v4l2_format fmt;
-               memset(&fmt, 0, sizeof(fmt));
+
                fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY;
-               if (ioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT") < 0)
-                       fprintf(stderr, "ioctl: VIDIOC_G_FMT failed\n");
-               else {
+               if (doioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT") == 0) {
                        if (set_overlay_fmt_out & FmtChromaKey)
                                fmt.fmt.win.chromakey = 
overlay_fmt_out.fmt.win.chromakey;
                        if (set_overlay_fmt_out & FmtGlobalAlpha)
                                fmt.fmt.win.global_alpha = 
overlay_fmt_out.fmt.win.global_alpha;
-                       if (ioctl(fd, VIDIOC_S_FMT, &fmt, "VIDIOC_S_FMT") < 0)
-                               fprintf(stderr, "ioctl: VIDIOC_S_FMT failed\n");
+                       doioctl(fd, VIDIOC_S_FMT, &fmt, "VIDIOC_S_FMT");
                }
        }
 
        if (options[OptSetFBuf]) {
                struct v4l2_framebuffer fb;
-               if (ioctl(fd, VIDIOC_G_FBUF, &fb, "VIDIOC_G_FBUF") < 0)
-                       fprintf(stderr, "ioctl: VIDIOC_G_FBUF failed\n");
-               else {
+
+               if (doioctl(fd, VIDIOC_G_FBUF, &fb, "VIDIOC_G_FBUF") == 0) {
                        fb.flags &= ~set_fbuf;
                        fb.flags |= fbuf.flags;
-                       if (ioctl(fd, VIDIOC_S_FBUF, &fb) < 0)
-                               fprintf(stderr, "ioctl: VIDIOC_S_FBUF 
failed\n");
+                       doioctl(fd, VIDIOC_S_FBUF, &fb, "VIDIOC_S_FBUF");
                }
        }
 
@@ -1763,69 +1748,53 @@ int main(int argc, char **argv)
        if (options[OptGetVideoFormat]) {
                vfmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
                if (doioctl(fd, VIDIOC_G_FMT, &vfmt, "VIDIOC_G_FMT") == 0)
-                       if (printfmt(vfmt) != 0)
-                               fprintf(stderr, "error printing result\n");
+                       printfmt(vfmt);
        }
 
        if (options[OptGetVideoOutFormat]) {
                vfmt_out.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
                if (doioctl(fd, VIDIOC_G_FMT, &vfmt_out, "VIDIOC_G_FMT") == 0)
-                       if (printfmt(vfmt_out) != 0)
-                               fprintf(stderr, "error printing result\n");
+                       printfmt(vfmt_out);
        }
 
        if (options[OptGetOverlayFormat]) {
                struct v4l2_format fmt;
-               memset(&fmt, 0, sizeof(fmt));
+
                fmt.type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
                if (doioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT") == 0)
-                       if (printfmt(fmt) != 0)
-                               fprintf(stderr, "error printing result\n");
+                       printfmt(fmt);
        }
 
        if (options[OptGetOutputOverlayFormat]) {
                struct v4l2_format fmt;
-               memset(&fmt, 0, sizeof(fmt));
+
                fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY;
                if (doioctl(fd, VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT") == 0)
-                       if (printfmt(fmt) != 0)
-                               fprintf(stderr, "error printing result\n");
+                       printfmt(fmt);
        }
 
        if (options[OptGetSlicedVbiFormat]) {
                vbi_fmt.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
-               if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt,
-                       "VIDIOC_G_FMT") == 0)
-                       if (printfmt(vbi_fmt) != 0)
-                               fprintf(stderr,
-                                       "error printing result\n");
+               if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt, "VIDIOC_G_FMT") == 0)
+                       printfmt(vbi_fmt);
        }
 
        if (options[OptGetSlicedVbiOutFormat]) {
                vbi_fmt_out.type = V4L2_BUF_TYPE_SLICED_VBI_OUTPUT;
-               if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt_out,
-                       "VIDIOC_G_FMT") == 0)
-                       if (printfmt(vbi_fmt_out) != 0)
-                               fprintf(stderr,
-                                       "error printing result\n");
+               if (doioctl(fd, VIDIOC_G_FMT, &vbi_fmt_out, "VIDIOC_G_FMT") == 
0)
+                       printfmt(vbi_fmt_out);
        }
 
        if (options[OptGetVbiFormat]) {
                raw_fmt.type = V4L2_BUF_TYPE_VBI_CAPTURE;
-               if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt,
-                       "VIDIOC_G_FMT") == 0)
-                       if (printfmt(raw_fmt) != 0)
-                               fprintf(stderr,
-                                       "error printing result\n");
+               if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt, "VIDIOC_G_FMT") == 0)
+                       printfmt(raw_fmt);
        }
 
        if (options[OptGetVbiOutFormat]) {
                raw_fmt_out.type = V4L2_BUF_TYPE_VBI_OUTPUT;
-               if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt_out,
-                       "VIDIOC_G_FMT") == 0)
-                       if (printfmt(raw_fmt_out) != 0)
-                               fprintf(stderr,
-                                       "error printing result\n");
+               if (doioctl(fd, VIDIOC_G_FMT, &raw_fmt_out, "VIDIOC_G_FMT") == 
0)
+                       printfmt(raw_fmt_out);
        }
 
        if (options[OptGetFBuf]) {
@@ -2188,5 +2157,5 @@ int main(int argc, char **argv)
        }
 
        close(fd);
-       exit(0);
-}
+       exit(app_result);
+}


---

Patch is available at: 
http://linuxtv.org/hg/v4l-dvb/rev/a1a4bd5721335f5afa01305b8b6799f6f9c9e9d0

_______________________________________________
linuxtv-commits mailing list
linuxtv-commits@linuxtv.org
http://www.linuxtv.org/cgi-bin/mailman/listinfo/linuxtv-commits

Reply via email to